Am I the only one who feels this is just a huge XY problem?
The example issue is merge
from swift-async-algorithms
in which you can't create a structured task which has a lifetime which matches the merge
operation.
Using current tools, this could be solved by having merge
receive a TaskGroup
parameter, which would determine the lifetime of the contained tasks (and hence, the merge
d stream). If you read a bit about structured tasks/nurseries, you'd realize that's how it's supposed to be used. However, this originates from garbage-collected languages, in which lifetimes must be made explicit.
A correct solution to the problem would be structured tasks of which lifetime is associated with a parent structure/class, relying on ARC. This would require asynchronous deinitializers.
In other words, this entire pitch is basically trying to get structured concurrency without using structured concurrency. In use cases where it's entirely appropriate to use structured concurrency. Instead of trying to figure out how to make structured concurrency work.