Struct AsyncTask

Source
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,

Source

pub fn new(receivers: ZeroOneOrMany<Receiver<T>>) -> Self
where T: Send + 'static,

Create a new AsyncTask from ZeroOneOrMany receivers

Source

pub fn from_future<F>(future: F) -> Self
where F: Future<Output = T> + Send + 'static, T: Send + 'static,

Create an AsyncTask from a future

Source

pub fn from_value(value: T) -> Self
where T: Send + 'static,

Create an AsyncTask from a value

Source

pub fn spawn<F>(f: F) -> Self
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Create an AsyncTask that spawns a blocking task

Trait Implementations§

Source§

impl<T> Future for AsyncTask<T>
where T: NotResult,

Source§

type Output = T

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<T: Send + 'static + NotResult> FutureExt<T> for AsyncTask<T>

Source§

fn map<U>(self, f: impl FnOnce(T) -> U + Send + 'static) -> AsyncTask<U>
where U: Send + 'static + NotResult,

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>
where U: Send + 'static + NotResult,

Executes a function when the future completes successfully.
Source§

fn on_error<U>( self, f: impl FnOnce(RecvError) -> U + Send + 'static, ) -> AsyncTask<U>
where U: Send + 'static + NotResult, T: Into<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>
where U: Send + 'static + NotResult,

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>
where U: Send + 'static + NotResult,

Maps the success value while preserving error state.
Source§

fn tap_ok(self, f: impl FnOnce(&T) + Send + 'static) -> AsyncTask<T>

Applies a function to the success value without consuming it.
Source§

fn tap_err(self, f: impl FnOnce(&RecvError) + Send + 'static) -> AsyncTask<T>

Applies a function to the error value without consuming it.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.