pub struct SpawnedTask<R> { /* private fields */ }
Expand description
Helper that provides a simple API to spawn a single task and join it.
Provides guarantees of aborting on Drop
to keep it cancel-safe.
Note that if the task was spawned with spawn_blocking
, it will only be
aborted if it hasn’t started yet.
Technically, it’s just a wrapper of a JoinHandle
overriding drop.
Implementations§
Source§impl<R: 'static> SpawnedTask<R>
impl<R: 'static> SpawnedTask<R>
pub fn spawn<T>(task: T) -> Self
pub fn spawn_blocking<T>(task: T) -> Self
Sourcepub async fn join(self) -> Result<R, JoinError>
pub async fn join(self) -> Result<R, JoinError>
Joins the task, returning the result of join (Result<R, JoinError>
).
Same as awaiting the spawned task, but left for backwards compatibility.
Sourcepub async fn join_unwind(self) -> Result<R, JoinError>
pub async fn join_unwind(self) -> Result<R, JoinError>
Joins the task and unwinds the panic if it happens.
Sourcepub async fn join_unwind_mut(&mut self) -> Result<R, JoinError>
pub async fn join_unwind_mut(&mut self) -> Result<R, JoinError>
Joins the task using a mutable reference and unwinds the panic if it happens.
This method is similar to join_unwind
, but takes a mutable
reference instead of consuming self
. This allows the SpawnedTask
to remain
usable after the call.
If called multiple times on the same task:
- If the task is still running, it will continue waiting for completion
- If the task has already completed successfully, subsequent calls will
continue to return the same
JoinError
indicating the task is finished - If the task panicked, the first call will resume the panic, and the program will not reach subsequent calls
Trait Implementations§
Source§impl<R: Debug> Debug for SpawnedTask<R>
impl<R: Debug> Debug for SpawnedTask<R>
Source§impl<R> Drop for SpawnedTask<R>
impl<R> Drop for SpawnedTask<R>
Source§impl<R> Future for SpawnedTask<R>
impl<R> Future for SpawnedTask<R>
Auto Trait Implementations§
impl<R> Freeze for SpawnedTask<R>
impl<R> RefUnwindSafe for SpawnedTask<R>
impl<R> Send for SpawnedTask<R>where
R: Send,
impl<R> Sync for SpawnedTask<R>where
R: Send,
impl<R> Unpin for SpawnedTask<R>
impl<R> UnwindSafe for SpawnedTask<R>
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
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
>.