Struct fuchsia_async::Task
source · pub struct Task<T>(/* private fields */);
Expand description
This is the same as a JoinHandle, except that the future will be cancelled when the task is dropped.
Implementations§
source§impl<T> Task<T>
impl<T> Task<T>
sourcepub fn detach_on_drop(self) -> JoinHandle<T> ⓘ
pub fn detach_on_drop(self) -> JoinHandle<T> ⓘ
Returns a JoinHandle
which will have detach-on-drop semantics.
source§impl Task<()>
impl Task<()>
sourcepub fn detach(self)
pub fn detach(self)
Detach this task so that it can run independently in the background.
Note: this is usually not what you want. This API severs the control flow from the
caller, making it impossible to return values (including errors). If your goal is to run
multiple futures concurrently, consider using [TaskGroup
] or other futures combinators
such as:
- [
futures::future::join
] - [
futures::future::select
] - [
futures::select
]
or their error-aware variants
- [
futures::future::try_join
] - [
futures::future::try_select
]
or their stream counterparts
- [
futures::stream::StreamExt::for_each
] - [
futures::stream::StreamExt::for_each_concurrent
] - [
futures::stream::TryStreamExt::try_for_each
] - [
futures::stream::TryStreamExt::try_for_each_concurrent
]
can meet your needs.
source§impl<T: Send + 'static> Task<T>
impl<T: Send + 'static> Task<T>
sourcepub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T> ⓘ
pub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T> ⓘ
Spawn a new task on the current executor.
The task may be executed on any thread(s) owned by the current executor.
See Task::local
for an equivalent that ensures locality.
The passed future will live until either (a) the future completes,
(b) the returned Task
is dropped while the executor is running, or
(c) the executor is destroyed; whichever comes first.
§Panics
spawn
may panic if not called in the context of an executor (e.g.
within a call to run
or run_singlethreaded
).
source§impl<T: 'static> Task<T>
impl<T: 'static> Task<T>
sourcepub fn local(future: impl Future<Output = T> + 'static) -> Task<T> ⓘ
pub fn local(future: impl Future<Output = T> + 'static) -> Task<T> ⓘ
Spawn a new task on the thread local executor.
The passed future will live until either (a) the future completes,
(b) the returned Task
is dropped while the executor is running, or
(c) the executor is destroyed; whichever comes first.
NOTE: This is not supported with a [SendExecutor
] and will cause a
runtime panic. Use Task::spawn
instead.
§Panics
local
may panic if not called in the context of a local executor (e.g.
within a call to run
or run_singlethreaded
).
Trait Implementations§
source§impl<T> From<JoinHandle<T>> for Task<T>
impl<T> From<JoinHandle<T>> for Task<T>
source§fn from(value: JoinHandle<T>) -> Self
fn from(value: JoinHandle<T>) -> Self
Auto Trait Implementations§
impl<T> Freeze for Task<T>
impl<T> !RefUnwindSafe for Task<T>
impl<T> Send for Task<T>where
T: Send,
impl<T> Sync for Task<T>where
T: Sync,
impl<T> Unpin for Task<T>
impl<T> !UnwindSafe for Task<T>
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<T> FutureExt for T
impl<T> FutureExt for T
§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f
. Read more§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
§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 more§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
§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 more§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>>
§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,
§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 = ()
>.§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<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
§type IntoFuture = F
type IntoFuture = F
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<F> TimeoutExt for Fwhere
F: Future,
impl<F> TimeoutExt for Fwhere
F: Future,
source§fn on_timeout<WT, OT>(self, time: WT, on_timeout: OT) -> OnTimeout<Self, OT> ⓘ
fn on_timeout<WT, OT>(self, time: WT, on_timeout: OT) -> OnTimeout<Self, OT> ⓘ
on_timeout
to produce a result
when the timeout occurs.source§fn on_stalled<OS>(
self,
timeout: Duration,
on_stalled: OS,
) -> OnStalled<Self, OS> ⓘ
fn on_stalled<OS>( self, timeout: Duration, on_stalled: OS, ) -> OnStalled<Self, OS> ⓘ
on_stalled
to produce a result
when the future hasn’t been otherwise polled within the timeout
.
This is a heuristic - spurious wakeups will keep the detection from triggering,
and moving all work to external tasks or threads with force the triggering early.§impl<F, T, E> TryFuture for F
impl<F, T, E> TryFuture for F
§impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
§fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
Sink
]. Read more