pub struct Task<T>(/* private fields */);Expand description
Task is a primitive that allows work to happen in the background.
It implements Future so you can .await on it.
If you drop a task it will be cancelled immediately. Calling Task::detach allows
the task to continue running, but with no way to return a value.
Implementations§
Source§impl<T> Task<T>
impl<T> Task<T>
Sourcepub fn from_async_task(task: Task<T, RunnableMeta>) -> Task<T> ⓘ
pub fn from_async_task(task: Task<T, RunnableMeta>) -> Task<T> ⓘ
Creates a Task from an async_task::Task
pub fn is_ready(&self) -> bool
Sourcepub fn fallible(self) -> FallibleTask<T> ⓘ
pub fn fallible(self) -> FallibleTask<T> ⓘ
Converts this task into a fallible task that returns Option<T>.
Source§impl Task<Box<dyn Any + Sync + Send>>
impl Task<Box<dyn Any + Sync + Send>>
Sourcepub fn downcast<T>(self) -> Task<T> ⓘ
pub fn downcast<T>(self) -> Task<T> ⓘ
Reinterprets the boxed output as a concrete T via downcast on
completion. Used by LocalExecutor::spawn_dedicated and
BackgroundExecutor::spawn_dedicated to recover the user closure’s
Fut::Output from the dyn-safe Scheduler::spawn_dedicated.
Panics on poll if the inner output is not in fact a T – a logic
error in whatever produced the inner task, since the downcast type is
chosen by the caller of downcast.
Trait Implementations§
Source§impl<T, E> TaskExt<T, E> for Task<Result<T, E>>
impl<T, E> TaskExt<T, E> for Task<Result<T, E>>
Source§fn detach_and_log_err(self, cx: &App)
fn detach_and_log_err(self, cx: &App)
Source§fn detach_and_log_err_with_backtrace(self, cx: &App)
fn detach_and_log_err_with_backtrace(self, cx: &App)
Self::detach_and_log_err, but uses {:?} formatting on failure so anyhow::Error
values emit their full backtrace. Prefer detach_and_log_err unless a backtrace is wanted.Auto Trait Implementations§
impl<T> !RefUnwindSafe for Task<T>
impl<T> !UnwindSafe for Task<T>
impl<T> Freeze for Task<T>where
T: Freeze,
impl<T> Send for Task<T>where
T: Send,
impl<T> Sync for Task<T>where
T: Sync,
impl<T> Unpin for Task<T>where
T: Unpin,
impl<T> UnsafeUnpin for Task<T>where
T: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F> FutureExt for F
impl<F> FutureExt for F
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§impl<F> FutureExt for F
impl<F> FutureExt for F
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§impl<T> FutureExt for Twhere
T: Future,
impl<T> FutureExt for Twhere
T: Future,
Source§fn with_timeout(
self,
timeout: Duration,
executor: &BackgroundExecutor,
) -> WithTimeout<T>where
T: Sized,
fn with_timeout(
self,
timeout: Duration,
executor: &BackgroundExecutor,
) -> WithTimeout<T>where
T: Sized,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn delay(self, dur: Duration) -> DelayFuture<Self>where
Self: Sized,
fn delay(self, dur: Duration) -> DelayFuture<Self>where
Self: Sized,
Source§fn flatten(self) -> FlattenFuture<Self, <Self::Output as IntoFuture>::Future>
fn flatten(self) -> FlattenFuture<Self, <Self::Output as IntoFuture>::Future>
Source§fn race<F>(self, other: F) -> Race<Self, F>
fn race<F>(self, other: F) -> Race<Self, F>
Source§fn try_race<F, T, E>(self, other: F) -> TryRace<Self, F>
fn try_race<F, T, E>(self, other: F) -> TryRace<Self, F>
Source§fn join<F>(self, other: F) -> Join<Self, F>
fn join<F>(self, other: F) -> Join<Self, F>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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