pub struct Task<'t, T> { /* private fields */ }
Expand description
An asynchronous result which may be evaluated with .await
, or by using
blocking operations with an optional timeout.
Implementations§
Source§impl<'t, T> Task<'t, T>
impl<'t, T> Task<'t, T>
Sourcepub fn from_poll<F>(f: F) -> Self
pub fn from_poll<F>(f: F) -> Self
Create a new Task
from a function returning Poll<T>
. If the
function is already boxed, then it would be more efficient to use
Task::from
.
Sourcepub fn from_future<F>(f: F) -> Self
pub fn from_future<F>(f: F) -> Self
Create a new Task
from a Future<T>
. If the future is already boxed,
then it would be more efficient to use Task::from
.
Sourcepub fn from_value(result: T) -> Selfwhere
T: Send + 't,
pub fn from_value(result: T) -> Selfwhere
T: Send + 't,
Create a new Task
from a result value.
Sourcepub fn map<'m, F, R>(self, f: F) -> Task<'m, R> ⓘ
pub fn map<'m, F, R>(self, f: F) -> Task<'m, R> ⓘ
Map the result of the Task
using a transformation function.
Sourcepub fn wait(self) -> T
pub fn wait(self) -> T
Resolve the Task
to its result, parking the current thread until
the result is available.
Sourcepub fn wait_deadline(self, expire: Instant) -> Result<T, Self>
pub fn wait_deadline(self, expire: Instant) -> Result<T, Self>
Resolve the Task
to its result, parking the current thread until
the result is available or the deadline is reached. If a timeout occurs
then the Err
result will contain the original Task
.
Sourcepub fn wait_timeout(self, timeout: Duration) -> Result<T, Self>
pub fn wait_timeout(self, timeout: Duration) -> Result<T, Self>
Resolve the Task
to its result, parking the current thread until
the result is available or the timeout expires. If a timeout does
occur then the Err
result will contain the original Task
.