Skip to main content

Barrier

Struct Barrier 

Source
pub struct Barrier { /* private fields */ }
Available on crate feature 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

Source

pub fn new(n: u32) -> Self

Creates a barrier for n participants.

Each generation completes when n calls to wait have arrived. Passing zero selects the same immediately completing behavior as passing one.

§Examples
use asyncband::barrier::Barrier;

let barrier = Barrier::new(3);
Source

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());

Trait Implementations§

Source§

impl Debug for Barrier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.