pub struct CancelToken { /* private fields */ }Expand description
Cancellation signal shared between caller and Lua thread.
Clone is cheap (Arc).
Two cancellation pathways are wired:
-
A Lua debug hook checks
is_cancelledeveryNLua instructions. This interrupts pure-Lua CPU-bound loops (while true do endetc), including loops inside coroutines that the Lua code itself creates. -
When the feature
tokiois enabled,cancelledprovides an async signal that fires as soon ascancelis called. Coroutine executors use it to stop a Lua coroutine even when it is suspended inside a Rust.await(e.g. acreate_async_functionawaiting a tokio child process), a state in which the debug hook cannot fire because no Lua instructions execute.
§Hierarchy
child_token derives a token that is cancelled
whenever its parent is. A parent holds its children weakly and a
child holds its parent strongly: a finished child disappears from
its parent without an explicit unregister, and a live grandchild
keeps the chain between it and the root alive.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn child_token(&self) -> CancelToken
pub fn child_token(&self) -> CancelToken
Derive a child token.
The child is cancelled when this token is cancelled (at once if it already is). Cancelling the child does not affect this token.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal cancellation.
Sets the atomic flag (observed by the Lua debug hook), notifies
all waiters of the async cancelled signal
when the tokio feature is enabled, and cancels every live
child token.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check whether cancellation has been requested.
Trait Implementations§
Source§impl Clone for CancelToken
impl Clone for CancelToken
Source§impl Debug for CancelToken
impl Debug for CancelToken
Auto Trait Implementations§
impl Freeze for CancelToken
impl RefUnwindSafe for CancelToken
impl Send for CancelToken
impl Sync for CancelToken
impl Unpin for CancelToken
impl UnsafeUnpin for CancelToken
impl UnwindSafe for CancelToken
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more