Async-await on stable Rust!

Sebastiaan Koppe mail at skoppe.eu
Fri Nov 8 09:57:59 UTC 2019


On Friday, 8 November 2019 at 02:13:28 UTC, rikki cattermole 
wrote:
> So from what I can tell, there are two aspects to this.
>
> 1. Future's which have custom executors which you must 
> explicitly call.
> 2. async/await which ties into the borrow checker and requires 
> await to be called so pretty much stack only.
>
> From previous discussion this isn't what we want in D.
> The previous designs discussed is an event loop poll based and 
> heap allocate the closure.
>
> It does mean that we need an event loop in druntime, but since 
> I am expecting to write up an event loop soon for the graphics 
> workgroup I'll add that to part of its requirements (with 
> -betterC compatible).

Please have a look at the approach taken by structured 
concurrency. Recently mentioned on this forum by John Belmonte: 
https://forum.dlang.org/post/rnqbswwwhdwkvvqvodlb@forum.dlang.org

Kotlin has taken that route as well and I have found working with 
it's concurrency very pleasant.

The central idea of structured concurrency (a term taken from 
structured programming) is to provide 'blocks' or nurseries where 
tasks (threads/fiber/coroutines) run concurrent, and only exit 
those blocks when all it's concurrent tasks are finished.

It is a simple restriction, but solves a lot of problems. You can 
follow the links provided in John Belmonte's posts for some more 
explanation.


More information about the Digitalmars-d mailing list