Struct grafix_toolbox::uses::Async::sync::Barrier [−]
pub struct Barrier { /* fields omitted */ }Expand description
A counter to synchronize multiple tasks at the same time.
Implementations
impl Barrier
impl Barrierpub async fn wait(&'_ self) -> BarrierWaitResult
pub async fn wait(&'_ self) -> BarrierWaitResultBlocks the current task until all tasks reach this point.
Barriers are reusable after all tasks have synchronized, and can be used continuously.
Returns a BarrierWaitResult indicating whether this task is the “leader”, meaning the
last task to call this method.
Examples
use async_lock::Barrier; use futures_lite::future; use std::sync::Arc; use std::thread; let barrier = Arc::new(Barrier::new(5)); for _ in 0..5 { let b = barrier.clone(); thread::spawn(move || { future::block_on(async { // The same messages will be printed together. // There will NOT be interleaving of "before" and "after". println!("before wait"); b.wait().await; println!("after wait"); }); }); }
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Barrierimpl UnwindSafe for BarrierBlanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = TShould always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> boolChecks if self is actually part of its subset T (and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SSUse with care! Same as self.to_subset but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SPThe inclusion map: converts self to the equivalent element of its superset.
pub fn vzip(self) -> V