I've made a small library demonstrating what I think represents a previously unexplored point in the "async task that borrow from their parent scope" API space. The basic idea is to use Future::poll as a way of verifying that the borrows of child tasks remain valid, and then wake the child tasks so they can try to do some work while their borrows are still valid. We then block inside the parent task's poll method until all the child tasks have yielded. This enables the parent future to be somewhat non-blocking. I think the idea is sound, but I haven't really talked to anyone else about it before now. I'm also not sure my implementation is sound. The API also isn't the prettiest, but that doesn't matter that much for now (the tests are honestly also not great).
Afaik this has been tried before, but Tokio's work-stealing scheduler makes it impossible to do this safely. At any time a future can be polled from a completely different thread, which invalidates the idea of "scoped" tasks.
This is sound, but will probably lead to deadlocks. Imagine that you have N cpus and then N different scopes get polled. They all wake up their child futures, but no child futures can run because all workers are occupied by the parent futures.
(Or it can be made sound - I have not looked at your concrete implementation.)
Yeah, that's another limitation I'm aware of (I really should've made my post more detailed). I've been contemplating making the scope work-stealing, but I'm a little hesitant of going that route, seeing as my main use-case for this is running it on top of tokio, a work-stealing runtime