pub struct Operation { /* private fields */ }Expand description
The caller’s handle on one engine call: where its progress goes and how to cancel it.
Clones share the sink and the cancel flag. Operation::default has id
0, discards progress, and has a fresh token.
use std::sync::mpsc;
use thunderstore_engine::progress::{Operation, OperationId};
let (tx, rx) = mpsc::channel();
let operation = Operation::new(OperationId(1)).with_progress(move |event| {
let _ = tx.send(event);
});
let cancel = operation.cancel_token();
cancel.cancel();
assert!(operation.is_cancelled());
assert!(rx.try_recv().is_err());Implementations§
Source§impl Operation
impl Operation
Sourcepub fn new(id: OperationId) -> Self
pub fn new(id: OperationId) -> Self
An operation with id id that discards progress, with a fresh token.
Sourcepub fn with_progress(self, sink: impl ProgressSink + 'static) -> Self
pub fn with_progress(self, sink: impl ProgressSink + 'static) -> Self
Sends this operation’s progress to sink.
Sourcepub fn with_cancel(self, token: CancelToken) -> Self
pub fn with_cancel(self, token: CancelToken) -> Self
Cancels this operation through token, for a caller that made the token
first.
Sourcepub fn id(&self) -> OperationId
pub fn id(&self) -> OperationId
The id every event from this operation carries.
Sourcepub fn cancel_token(&self) -> CancelToken
pub fn cancel_token(&self) -> CancelToken
A clone of this operation’s cancel token.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether cancellation was requested.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Operation
impl !UnwindSafe for Operation
impl Forget for Operation
impl Freeze for Operation
impl Move for Operation
impl Send for Operation
impl Sync for Operation
impl Unpin for Operation
impl UnsafeUnpin for Operation
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