pub struct Barrier { /* private fields */ }barrier only.Expand description
A synchronization primitive for multiple tasks that need to wait for each other.
See the module level documentation for more.
Implementations§
Source§impl Barrier
impl Barrier
Sourcepub async fn wait(&self) -> BarrierWaitResult
pub async fn wait(&self) -> BarrierWaitResult
Waits for all tasks to reach this point.
The barrier holds the current task until all n participants have arrived. The final
participant is designated as the leader for this generation.
§Cancel safety
This method is not cancellation safe.
An arrival is recorded when the future returned by wait is first polled. Once recorded,
the arrival is not retracted if that future is dropped before the barrier completes.
Cancellation therefore stops that caller from observing completion, but it does not make the
caller leave the current barrier generation.
Calling wait again after canceling a pending call records another arrival. Repeatedly
canceling and retrying can therefore cause a generation to complete with fewer than n live
wait futures. Callers that need to keep waiting after another operation completes first
should retain and continue polling the same wait future instead of creating a new one.
Returns a BarrierWaitResult that identifies whether this participant is the leader.
§Examples
use asyncband::barrier::Barrier;
let barrier = Barrier::new(1);
assert!(barrier.wait().await.is_leader());