pub trait CompletionFuture {
type Output;
// Required methods
unsafe fn poll(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Self::Output>;
unsafe fn poll_cancel(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<()>;
}Expand description
A Future that must be polled to completion.
All types that implement Future should also implement this.
A completion future has three states: running, cancelling and complete. Futures initially start
out in the running state. To progress the running state, users will call poll, which either
returns Poll::Pending to continue the running state or Poll::Ready to return a value and
reach the complete state.
At any time during the running state, users may call poll_cancel to initiate the cancelling
state. During this state, only poll_cancel should be called, and it can return
Poll::Pending to continue the cancelling state or Poll::Ready(()) to reach the
complete state.
Once the complete state has been reached, either by regular completion or after cancellation,
neither poll nor poll_cancel should be called again.
A violation of these rules can cause unexpected behaviour: the future may panic, block forever or return unexpected results. However, it must never cause undefined behaviour.
Required Associated Types§
Required Methods§
Sourceunsafe fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>
unsafe fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available.
This function should only be called when the future is in the running state.
§Safety
Once this function has been called and the type does not also implement Future, the user
must not drop or forget the future until it it has returned Poll::Ready or panicked.
Sourceunsafe fn poll_cancel(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()>
unsafe fn poll_cancel(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()>
Attempt to cancel the future, registering the current task for wakeup if has not finished cancelling yet.
This function should only be called from the running state or in the cancelling state. Once
this function returns Poll::Ready, the future should be considered complete and should
not be polled again.
Note that this may be called before poll has been called for the first
time.
§Safety
Once this function has been called and the type does not also implement Future, the user
must not drop or forget the future until it has returned Poll::Ready or panicked.