awaitgroup
awaitgroup copied to clipboard
Support for child waitgroup; Refactored test with tokio::test
What a good waitgroup implementation in rust! This PR does two things:
-
Support for child
WaitGroup. ChildWaitGroupcan deriveWorkers andwaitfor allWorkersfinish executing like a normalWaitGroup. ParentWaitGroupwill stop waiting only after the workers registered in it and its childWaitGroups finish executing, but the childWaitGroupwill stop waiting after its registered workers finish executing, regardless of the workers in parent. -
Refactored test with tokio::test In current tests, the runtime is built manually. Tokio provides macro
tokio::testto run a async test, and i used this macro to refactor all tests. Moreover, current tests only test whether theWaitGroupcan stop waiting or not, but whether theWaitGroupstops waiting after the all worker tasks finish is not tested. Time asserts were added to test whereWaitGroupstops waiting after the most time-consuming task finish. The test for childWaitGroupwere also added.
Hi, thanks for the contribution. What's the usecase for this?
Hi, thanks for the contribution. What's the usecase for this?
In my opinions, the child waitgroup is used along with the child context. You only want to wait for the tasks govened by a child context to finish when the child context is canceled, and when you cancel the top-level context, you want to wait all tasks to finish.
Hi, just getting back to this. I think this use case is served by just creating a second waitgroup within the child task. Cancellation should be propagated in the same way. I'm going to close this for now, if there's something I missed feel free to reopen it and let me know.