I have a main task that will continuously spawn other tasks. I don’t care for the results of the other tasks, but I do want to make sure all the other tasks have finished before the main task will finish. I don’t want to keep around a handle for each task because that will leak too many resources (the main task will run for a long time) and I don’t have a good place to clean up the handles.
In my synchronous/thread-based implementation, I’ve implemented this by spawning each task on a new thread, detaching each thread (by dropping the join handle immediately), and keeping track of the running thread count. I also use a condition variable that the main thread can wait on (once it’s done). Just before a secondary thread finishes, it will decrease the count, and if the count is now zero, notify the main thread.
How would I go about implementing the same using tokio/futures? Obviously, I can’t use the (blocking) CondVar primitive.