pub struct StopToken { /* private fields */ }Expand description
Tells background work when mirust wants it to stop.
Workers started with spawn receive one; exported functions can get one from
Call::stop_token. A token is stopped when mIRC unloads the
DLL or exits (see the module docs). Once stopped it stays stopped, even
if mIRC loads the DLL again while the work is still winding down.
Implementations§
Source§impl StopToken
impl StopToken
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Whether the work should stop.
Sourcepub fn wait_timeout(&self, timeout: Duration) -> bool
pub fn wait_timeout(&self, timeout: Duration) -> bool
Sleeps for up to timeout, waking early if the token is stopped.
Returns true if the token is stopped. Use it in place of thread::sleep so the
worker reacts to an unload immediately:
mirust::spawn(|stop| {
while !stop.wait_timeout(Duration::from_secs(30)) {
// periodic work
}
})
.expect("failed to start worker");Trait Implementations§
Auto Trait Implementations§
impl Freeze for StopToken
impl RefUnwindSafe for StopToken
impl Send for StopToken
impl Sync for StopToken
impl Unpin for StopToken
impl UnsafeUnpin for StopToken
impl UnwindSafe for StopToken
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