Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
It can be a bit tricky keeping everything alive in an async context. This is an umbrella issue for discussion and brainstorming of ideas.
For example, a nursery blocks until all underlying tasks have finished. This allows things defined at the top level of the nursery to be global state shared by reference across all tasks.
A common approach in use right now is to wrap state in a shared pointer and pass that state by copy to all callbacks but this might involve a lot of shared pointer copies.
Another approach could be to define a method like `Future<T> AsyncBind(function<Future<T>(S*)>>, shared_ptr<S>)` which guarantees the S* is valid until the future completes.
Those approaches also might help futures but then not be able to help async generators, especially if that generator is passed back to user code. In that case it might be helpful to have something like...
AsyncGenerator<T> AddFinallyCallback(AsyncGenerator<T>, function<void()>)
...or...
AsyncGenerator<T> BindToGenerator(function<AsyncGenerator<T>(S*)>, std::shared_ptr<S>)