The forked elephant in the room
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Tue Jan 16 06:38:16 UTC 2024
On 16/01/2024 3:25 PM, Mike Shah wrote:
> (As an aside, my Ph.D. work was in Java doing some concurrency studies
> on performance -- so eventually I'd like to do more research work in D
> on this topic)
If you would like a suggestion on this topic, may I suggest coroutines?
From what I've seen in my library implementation they are the right way
to do asynchronous coding and they are at the fore-front of concurrency
research.
What is very interesting is that in D, as long as a function is being
compiled the compiler could slice and dice it into a coroutine object
(such as a closure) without needing to be annotated as such explicitly.
It could be done implicitly upon the library struct that represents the
language coroutine constructor.
No async/await, no writing for asynchronously, just sequentially.
For these reasons I've told Adam Wilson that if I am to be involved with
an event loop library for PhobosV3, I would not consider it without such
a feature. Because the alternatives are either a hacked together
workaround that is fail heavy (fibers), or rather involved in how you
need to write (callbacks).
https://github.com/Project-Sidero/eventloop/blob/master/source/sidero/eventloop/coroutine/builder.d#L213
Lastly, what I call a future completion (a specific coroutine) is
probably one of my most genius ideas of all time. It allows things like
socket read to return a coroutine that will be triggered in say async
read mechanism, but work with the coroutine worker runner dependency
analysis.
https://github.com/Project-Sidero/eventloop/blob/master/source/sidero/eventloop/tasks/future_completion.d#L113
More information about the Digitalmars-d
mailing list