pub struct TaskToken { /* private fields */ }Expand description
Cancellation handle shared between the UI thread and one worker.
The UI thread keeps a clone and calls TaskToken::cancel; the worker
keeps another clone and polls TaskToken::is_cancelled between chunks
of work. Cancellation is cooperative: the worker decides where it is safe
to stop and then posts its final TaskCommand::Finished.
Implementations§
Source§impl TaskToken
impl TaskToken
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true once TaskToken::cancel was called.
Sourcepub fn sleep_or_cancelled(&self, duration: Duration) -> bool
pub fn sleep_or_cancelled(&self, duration: Duration) -> bool
Sleeps for up to duration, returning early if cancellation is requested.
Returns true if the full duration elapsed without cancellation, or false
immediately if cancellation was requested (either prior to this call or during the sleep).
Polling quantum is bounded (at most 25ms) to guarantee prompt cancellation response
without CPU spinning.
Trait Implementations§
Auto Trait Implementations§
impl Forget for TaskToken
impl Freeze for TaskToken
impl Move for TaskToken
impl RefUnwindSafe for TaskToken
impl Send for TaskToken
impl Sync for TaskToken
impl Unpin for TaskToken
impl UnsafeUnpin for TaskTokenwhere
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
impl UnwindSafe for TaskToken
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