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
. ChildWaitGroup
can deriveWorker
s andwait
for allWorkers
finish executing like a normalWaitGroup
. ParentWaitGroup
will stop waiting only after the workers registered in it and its childWaitGroup
s finish executing, but the childWaitGroup
will 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::test
to run a async test, and i used this macro to refactor all tests. Moreover, current tests only test whether theWaitGroup
can stop waiting or not, but whether theWaitGroup
stops waiting after the all worker tasks finish is not tested. Time asserts were added to test whereWaitGroup
stops waiting after the most time-consuming task finish. The test for childWaitGroup
were 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.