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> SpawnedTask<R>where
R: 'static,
impl<R> SpawnedTask<R>where
R: 'static,
pub fn spawn<T>(task: T) -> SpawnedTask<R> ⓘ
pub fn spawn_blocking<T>(task: T) -> SpawnedTask<R> ⓘ
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
JoinErrorindicating 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 for SpawnedTask<R>where
R: Debug,
impl<R> Debug for SpawnedTask<R>where
R: Debug,
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> UnsafeUnpin for SpawnedTask<R>
impl<R> UnwindSafe for SpawnedTask<R>
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
impl<T> Allocation for T
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<O, F> ElapsedComputeFutureExt for Fwhere
F: Future<Output = O>,
impl<O, F> ElapsedComputeFutureExt for Fwhere
F: Future<Output = O>,
Source§fn with_elapsed_compute(self, elapsed_compute: Time) -> ElapsedComputeFuture<F>
fn with_elapsed_compute(self, elapsed_compute: Time) -> ElapsedComputeFuture<F>
Future::poll
call is accumulated into elapsed_compute. See ElapsedComputeFuture
for a full description of what is and is not measured.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 with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
fn with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
CancellationToken::run_until_cancelled,
but with the advantage that it is easier to write fluent call chains. Read moreSource§fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
CancellationToken::run_until_cancelled_owned,
but with the advantage that it is easier to write fluent call chains. Read moreSource§impl<F> FutureExt for Fwhere
F: Future,
impl<F> FutureExt for Fwhere
F: Future,
Source§fn into_local_ffi<'a>(self) -> LocalBorrowingFfiFuture<'a, Self::Output>where
Self: 'a,
fn into_local_ffi<'a>(self) -> LocalBorrowingFfiFuture<'a, Self::Output>where
Self: 'a,
Future into a FFI-compatible LocalFfiFuture.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