pub struct Pending<T> { /* private fields */ }Expand description
A task whose one result a window collects on a later frame.
An egui window cannot await. It starts work such as a dial or a device
open with spawn, and asks poll on each
frame until the result is there. The task repaints the window when it
finishes, so the window draws the result at once. Dropping the handle
aborts the task.
§Examples
use std::task::Poll;
use moq_ext_egui::Pending;
let task = pending.get_or_insert_with(|| Pending::spawn(ctx, async { 42 }));
if let Poll::Ready(result) = task.poll() {
println!("finished with {result:?}");
*pending = None;
}Implementations§
Source§impl<T: Send + 'static> Pending<T>
impl<T: Send + 'static> Pending<T>
Sourcepub fn spawn_with_late(
ctx: &Context,
future: impl Future<Output = T> + Send + 'static,
late: impl FnOnce(T) + Send + 'static,
) -> Self
pub fn spawn_with_late( ctx: &Context, future: impl Future<Output = T> + Send + 'static, late: impl FnOnce(T) + Send + 'static, ) -> Self
Runs future in a task, and hands a result nobody waits for any more to late.
For a result that holds something to close, such as a session that
connected after the window gave up on it. The task can only finish
late after cancel, since a drop aborts it.
§Panics
Panics when called outside a Tokio runtime.
Sourcepub fn poll(&mut self) -> Poll<Option<T>>
pub fn poll(&mut self) -> Poll<Option<T>>
Returns the result once the task has finished.
Returns Ready(None) for a task that stopped without a result, which
happens after cancel, and while the runtime shuts
down.
Sourcepub fn cancel(&mut self) -> Option<T>
pub fn cancel(&mut self) -> Option<T>
Stops the task and returns a result it delivered before it stopped.
Sourcepub async fn wait(self) -> Option<T>
pub async fn wait(self) -> Option<T>
Waits for the result, keeping the task alive until it is there.
For a task that another task takes over, such as a connection start
that a restart must wait for and close before it starts again, where
cancel would drop the result unclosed. Returns None
for a task that stopped without a result, as poll does.
Cancel safe: dropping the future aborts the task, as dropping the handle does.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Pending<T>
impl<T> !UnwindSafe for Pending<T>
impl<T> Freeze for Pending<T>
impl<T> Send for Pending<T>where
T: Send,
impl<T> Sync for Pending<T>where
T: Send,
impl<T> Unpin for Pending<T>
impl<T> UnsafeUnpin for Pending<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more