Skip to main content

Pending

Struct Pending 

Source
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>

Source

pub fn spawn( ctx: &Context, future: impl Future<Output = T> + Send + 'static, ) -> Self

Runs future in a task and repaints ctx when it finishes.

A result that arrives after cancel or a drop is dropped.

§Panics

Panics when called outside a Tokio runtime.

Source

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.

Source

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.

Source

pub fn cancel(&mut self) -> Option<T>

Stops the task and returns a result it delivered before it stopped.

Source

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§

Source§

impl<T: Debug> Debug for Pending<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more