pub struct TaskHandle<T, E = String> { /* private fields */ }Expand description
Implementations§
Source§impl<T, E> TaskHandle<T, E>
impl<T, E> TaskHandle<T, E>
Sourcepub fn is_current(&self) -> bool
pub fn is_current(&self) -> bool
Whether this run is still the task’s current one. A worker may poll this to stop early after being superseded.
Sourcepub fn set_progress(&self, progress: f32) -> bool
pub fn set_progress(&self, progress: f32) -> bool
Report determinate progress, clamped to 0..=1. Repeating the current
value does not notify. NaN reports indeterminate progress.
Sourcepub fn cancel(self) -> bool
pub fn cancel(self) -> bool
Abandon the run: back to Idle, or to the previous result after a
Task::refresh. Ignored if the run was already retired.
Sourcepub fn run<Work>(
self,
work: Work,
) -> impl Future<Output = bool> + use<T, E, Work>
pub fn run<Work>( self, work: Work, ) -> impl Future<Output = bool> + use<T, E, Work>
Wrap work so its output completes this run. Spawn the returned
future on any executor; it resolves to whether the result was stored.
Dropping it before work finishes cancels the run.
ⓘ
let handle = results.refresh();
let progress = handle.clone();
wasm_bindgen_futures::spawn_local(async move {
handle
.run(async move {
progress.set_progress(0.5);
fetch_results().await
})
.await;
});pub fn finish(self, value: T) -> bool
pub fn fail(self, error: E) -> bool
Sourcepub fn complete(self, result: Result<T, E>) -> bool
pub fn complete(self, result: Result<T, E>) -> bool
Store the run’s result unless the run was retired. Returns whether it was stored.
pub fn task(&self) -> &Task<T, E>
Trait Implementations§
Source§impl<T, E> Clone for TaskHandle<T, E>
impl<T, E> Clone for TaskHandle<T, E>
Source§fn clone(&self) -> TaskHandle<T, E>
fn clone(&self) -> TaskHandle<T, E>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T, E> Forget for TaskHandle<T, E>
impl<T, E> Freeze for TaskHandle<T, E>
impl<T, E> Move for TaskHandle<T, E>
impl<T, E> RefUnwindSafe for TaskHandle<T, E>where
Task<T, E>: RefUnwindSafe,
impl<T, E> Send for TaskHandle<T, E>
impl<T, E> Sync for TaskHandle<T, E>
impl<T, E> Unpin for TaskHandle<T, E>
impl<T, E> UnsafeUnpin for TaskHandle<T, E>where
Task<T, E>: UnsafeUnpin,
impl<T, E> UnwindSafe for TaskHandle<T, E>where
Task<T, E>: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.