Expand description
Facility to wait for a dynamic set of tasks to complete, with a single waiter and multiple waitees (things that are waited for). Notably, each waitee can also start more work to be waited for.
§Implementation Details
The implementation of waiting in this module is just a wrapper around
tokio::sync::mpsc::channel. A WaitGroup holds the unique
tokio::sync::mpsc::Receiver and each WaitGuard holds a
tokio::sync::mpsc::Sender. Despite this simple implementation, the
WaitGroup and WaitGuard wrappers are useful to make this discoverable.
Structs§
- Wait
Group - Manager for a particular wait group. This can spawn a number of
WaitGuards and it can then wait for them to all complete. - Wait
Guard - RAII guard held by a task which is being waited for.
Functions§
- fibonacci_
waiter_ 🔒example - Demonstrates use of the
WaitGroupandWaitGuardto (very inefficiently) compute the Fibonacci numberF(n)using recursive channels. - fibonacci_
waiter_ 🔒example_ task - An inefficient Fibonacci implementation. This computes
F(n)by sending byn-1andn-2back into the channel. This shows how one work item can create multiple subsequent work items.