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) -> Self
pub fn new(task: T, context: TaskContext) -> Self
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 Self>, _cx: &mut Context<'_>) -> Poll<Self::Output>
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::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).