pub struct PulseEvent { /* private fields */ }Expand description
A PulseEvent
An event represents a boolean condition that can be waited on until signaled. This allows a thread to block and wait for another thread to set the event. Until the event is manually reset waiting will return immediately.
§Examples
use std::thread;
use std::time::Duration;
use win_events::{Event, PulseEvent};
let evt_started = PulseEvent::new();
let evt_started2 = evt_started.clone();
// spawn a thread and set the cloned event
thread::spawn(move|| {
thread::sleep(Duration::from_millis(1));
evt_started2.set();
});
// Wait for the started event
let wait_result = evt_started.wait(Duration::from_millis(100)).unwrap();
assert!(wait_result);Implementations§
Source§impl PulseEvent
impl PulseEvent
Sourcepub fn new() -> PulseEvent
pub fn new() -> PulseEvent
Sourcepub fn is_set(&self) -> bool
pub fn is_set(&self) -> bool
Gets the current state of the event, this always returns false for a pulse event.
§Examples
use win_events::PulseEvent;
let evt = PulseEvent::new();
assert!(!evt.is_set())Sourcepub fn set(&self)
pub fn set(&self)
Sets the event and fires a signal to any threads waiting on the event.
§Examples
use win_events::PulseEvent;
let evt = PulseEvent::new();
evt.set();
assert!(!evt.is_set())Sourcepub fn clear(&self)
pub fn clear(&self)
Clears the event
§Examples
use win_events::PulseEvent;
let evt = PulseEvent::new();
evt.clear();
assert!(!evt.is_set())Sourcepub fn wait(&self, dur: Duration) -> Result<bool, Box<dyn Error>>
pub fn wait(&self, dur: Duration) -> Result<bool, Box<dyn Error>>
Waits on the event to be set
§Examples
use std::thread::{sleep, spawn};
use std::time::Duration;
use win_events::PulseEvent;
let evt = PulseEvent::new();
let evt_inner = evt.clone();
let worker = spawn(move || {
sleep(Duration::from_millis(3));
evt_inner.set()
});
let wait_result = evt.wait(Duration::from_millis(100)).unwrap();
assert!(wait_result)Trait Implementations§
Source§impl Clone for PulseEvent
impl Clone for PulseEvent
Source§fn clone(&self) -> PulseEvent
fn clone(&self) -> PulseEvent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PulseEvent
impl !RefUnwindSafe for PulseEvent
impl Send for PulseEvent
impl Sync for PulseEvent
impl Unpin for PulseEvent
impl !UnwindSafe for PulseEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more