pub struct CancelToken { /* private fields */ }Expand description
A shared, thread-safe “please stop” flag, with an optional progress observer.
Clones share the flag: cancel any clone and every holder sees it. Optionally it
also polls a caller-supplied function (see CancelToken::with_poll), so a
host that already keeps its own stop flag need not mirror it into this one.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn with_poll(poll: impl Fn() -> bool + Send + Sync + 'static) -> Self
pub fn with_poll(poll: impl Fn() -> bool + Send + Sync + 'static) -> Self
A token that is also cancelled once poll returns true.
poll is called from whichever thread reaches a checkpoint, worker threads
included, possibly from several at once, so it must be cheap and
thread-safe. Once it has returned true the token stays cancelled and
poll is not called again.
Sourcepub fn with_progress(
self,
progress: impl Fn(&'static str, f64) + Send + Sync + 'static,
) -> Self
pub fn with_progress( self, progress: impl Fn(&'static str, f64) + Send + Sync + 'static, ) -> Self
This token (still sharing its flag and poll function with its clones),
with progress told of the solve’s progress: a stage name and a
fraction in [0, 1], or -1 when the stage’s extent is unknown.
Called from the solver’s worker threads, possibly several at once, so it must be thread-safe. The search reports at most a few hundred times.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether the token has been cancelled (or its poll function says so).