pub struct AsyncTask<T>where
T: NotResult,{ /* private fields */ }Expand description
Generic async task wrapper for single operations
This wraps a oneshot::Receiver and implements Future to provide a concrete return type instead of boxed futures or async fn.
IMPORTANT: AsyncTask must never return Result types - all error handling should be done internally before creating the AsyncTask.
Implementations§
Source§impl<T> AsyncTask<T>where
T: NotResult,
impl<T> AsyncTask<T>where
T: NotResult,
Sourcepub fn new(receivers: ZeroOneOrMany<Receiver<T>>) -> Selfwhere
T: Send + 'static,
pub fn new(receivers: ZeroOneOrMany<Receiver<T>>) -> Selfwhere
T: Send + 'static,
Create a new AsyncTask from ZeroOneOrMany receivers
Sourcepub fn from_future<F>(future: F) -> Self
pub fn from_future<F>(future: F) -> Self
Create an AsyncTask from a future
Sourcepub fn from_value(value: T) -> Selfwhere
T: Send + 'static,
pub fn from_value(value: T) -> Selfwhere
T: Send + 'static,
Create an AsyncTask from a value
Trait Implementations§
Source§impl<T: Send + 'static + NotResult> FutureExt<T> for AsyncTask<T>
impl<T: Send + 'static + NotResult> FutureExt<T> for AsyncTask<T>
Source§fn map<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
fn map<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
Maps the success value of the future to a new type using the provided function.
Source§fn on_ok<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
fn on_ok<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
Executes a function when the future completes successfully.
Source§fn on_error<U>(
self,
f: impl FnOnce(RecvError) -> U + Send + 'static,
) -> AsyncTask<U> ⓘ
fn on_error<U>( self, f: impl FnOnce(RecvError) -> U + Send + 'static, ) -> AsyncTask<U> ⓘ
Executes a function when the future encounters an error.
Source§fn on_result<U>(
self,
f: impl FnOnce(Result<T, RecvError>) -> U + Send + 'static,
) -> AsyncTask<U> ⓘ
fn on_result<U>( self, f: impl FnOnce(Result<T, RecvError>) -> U + Send + 'static, ) -> AsyncTask<U> ⓘ
Handles both success and error cases with a result handler.
Source§fn map_ok<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
fn map_ok<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U> ⓘ
Maps the success value while preserving error state.
Auto Trait Implementations§
impl<T> Freeze for AsyncTask<T>
impl<T> NotResult for AsyncTask<T>
impl<T> !RefUnwindSafe for AsyncTask<T>
impl<T> Send for AsyncTask<T>where
T: Send,
impl<T> Sync for AsyncTask<T>where
T: Send,
impl<T> Unpin for AsyncTask<T>
impl<T> !UnwindSafe for AsyncTask<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
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more