pub struct TaskFuture<T> { /* private fields */ }Expand description
A future adapter that executes a Task on first poll.
§Execution semantics
The wrapped task runs synchronously inside the first poll call on the
polling thread — this adapter does not offload work to an executor, does
not yield mid-task, and never returns Poll::Pending. It exists so a
synchronous task can be awaited from async code; the .await completes in
one poll, blocking the async worker for the task’s full duration. Offload
long-running tasks to a blocking pool instead of awaiting them directly on
an async executor.
§Fused
Like core::future::Ready and other std-convention one-shot futures,
polling again after completion is a contract violation and panics.
Implementations§
Source§impl<T> TaskFuture<T>where
T: Task,
impl<T> TaskFuture<T>where
T: Task,
Sourcepub fn new(task: T, context: TaskContext) -> TaskFuture<T> ⓘ
pub fn new(task: T, context: TaskContext) -> TaskFuture<T> ⓘ
Create a new task future.
Sourcepub fn context(&self) -> &TaskContext
pub fn context(&self) -> &TaskContext
Get the task context.
Trait Implementations§
Source§impl<T> Future for TaskFuture<T>
impl<T> Future for TaskFuture<T>
Source§fn poll(
self: Pin<&mut TaskFuture<T>>,
_cx: &mut Context<'_>,
) -> Poll<<TaskFuture<T> as Future>::Output>
fn poll( self: Pin<&mut TaskFuture<T>>, _cx: &mut Context<'_>, ) -> Poll<<TaskFuture<T> as Future>::Output>
Executes the task synchronously and returns Poll::Ready on the first
call; see the type-level docs for the blocking semantics.
§Panics
Panics if polled again after it has returned Poll::Ready (fused
one-shot contract; a completed future has no result to hand out and no
waker-based path by which Pending could ever resolve).
Auto Trait Implementations§
impl<T> Freeze for TaskFuture<T>
impl<T> RefUnwindSafe for TaskFuture<T>where
Option<T>: RefUnwindSafe,
impl<T> Send for TaskFuture<T>
impl<T> Sync for TaskFuture<T>
impl<T> Unpin for TaskFuture<T>
impl<T> UnsafeUnpin for TaskFuture<T>where
Option<T>: UnsafeUnpin,
impl<T> UnwindSafe for TaskFuture<T>where
Option<T>: UnwindSafe,
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>.