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>) -> Self
pub fn from_async_task(task: Task<T, RunnableMeta>) -> Self
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 + Send + Sync>>
impl Task<Box<dyn Any + Send + Sync>>
Sourcepub fn downcast<T: Send + Sync + 'static>(self) -> Task<T> ⓘ
pub fn downcast<T: Send + Sync + 'static>(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§
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<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>.