Struct rsevents_extra::CountdownEvent
source · pub struct CountdownEvent { /* private fields */ }
Implementations§
source§impl CountdownEvent
impl CountdownEvent
A countdown event is a special type of ManualResetEvent
that makes it easy to wait for a
given number of tasks to complete asynchronously, and then carry out some action. A countdown
event is first initialized with a count equal to the number of outstanding tasks, and each time
a task is completed, CountdownEvent::tick()
is called. A call to
CountdownEvent::wait()
will block until all outstanding tasks have
completed and the internal counter reaches 0.
Countdown events are thread-safe and may be wrapped in an Arc
to easily
share across threads.
sourcepub fn new(count: usize) -> Self
pub fn new(count: usize) -> Self
Creates a new countdown event with the internal count initialized to count
. If a count of
zero is specified, the event is immediately set.
sourcepub fn tick(&self)
pub fn tick(&self)
Decrements the internal countdown. When the internal countdown reaches zero, the countdown
event enters a set state and any outstanding or future calls to
Awaitable::wait()
will be let through without blocking (until the event is reset).
Trait Implementations§
source§impl Awaitable for CountdownEvent
impl Awaitable for CountdownEvent
source§fn wait(&self)
fn wait(&self)
Waits for the internal countdown of the CountdownEvent
to reach zero.
source§fn wait0(&self) -> bool
fn wait0(&self) -> bool
false
immediately if it is not
set. Note that this is not the same as calling Awaitable::wait_for()
with a Duration
of
zero, as the calling thread never yields. Read moresource§fn wait_for(&self, limit: Duration) -> bool
fn wait_for(&self, limit: Duration) -> bool
limit
waiting for it to be set.
Returns true
if the event was originally set or if it was signalled within the specified
duration, and false
otherwise (if the timeout elapsed without the event becoming set). Read more