awaitgroup icon indicating copy to clipboard operation
awaitgroup copied to clipboard

Support for child waitgroup; Refactored test with tokio::test

Open YoshieraHuang opened this issue 3 years ago • 2 comments

What a good waitgroup implementation in rust! This PR does two things:

  1. Support for child WaitGroup. Child WaitGroup can derive Workers and wait for all Workers finish executing like a normal WaitGroup. Parent WaitGroup will stop waiting only after the workers registered in it and its child WaitGroups finish executing, but the child WaitGroup will stop waiting after its registered workers finish executing, regardless of the workers in parent.

  2. 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 the WaitGroup can stop waiting or not, but whether the WaitGroup stops waiting after the all worker tasks finish is not tested. Time asserts were added to test where WaitGroup stops waiting after the most time-consuming task finish. The test for child WaitGroup were also added.

YoshieraHuang avatar Jul 14 '21 07:07 YoshieraHuang

Hi, thanks for the contribution. What's the usecase for this?

ibraheemdev avatar Jul 16 '21 02:07 ibraheemdev

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.

YoshieraHuang avatar Jul 16 '21 02:07 YoshieraHuang

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.

ibraheemdev avatar Jul 15 '23 21:07 ibraheemdev