Skip to main content

DispatcherOperation

Struct DispatcherOperation 

Source
pub struct DispatcherOperation<R = ()> { /* private fields */ }
Expand description

Represents an object used to interact with a job that has been posted to the Dispatcher queue.

The handle can be cloned and sent to other threads. It is also a Future that resolves when the operation has completed (Ok(result)) or has been aborted (Err(OperationCanceledError)).

A panic raised by the callback is the equivalent of an exception in the reference implementation: it is captured when the callback runs and re-raised by wait, result and when the future is polled.

Implementations§

Source§

impl<R: 'static> DispatcherOperation<R>

Source

pub fn status(&self) -> DispatcherOperationStatus

The current status of the operation.

Source

pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ

The dispatcher the operation was queued on.

Source

pub fn priority(&self) -> DispatcherPriority

Source

pub fn set_priority(&self, value: DispatcherPriority)

Changes the priority of the operation. A queued operation keeps its position relative to the other operations of the new priority.

Source

pub fn aborted( &self, handler: impl Fn() + Send + Sync + 'static, ) -> Rc<dyn IDisposable>

An event that is raised when the operation is aborted or canceled.

The handler runs on the thread that aborts the operation.

Source

pub fn completed( &self, handler: impl Fn() + Send + Sync + 'static, ) -> Rc<dyn IDisposable>

An event that is raised when the operation completes.

The handler runs on the dispatcher thread.

Source

pub fn abort(&self) -> bool

Removes a pending operation from the queue. Returns false when the operation is no longer pending.

Source

pub fn wait(&self) -> Result<(), OperationCanceledError>

Waits for this operation to complete.

On the dispatcher thread this pumps the queue (nesting a frame when the operation has a background priority and the platform supports run loops). On any other thread it blocks.

Returns Err when the operation was aborted.

§Panics

Re-raises the panic of the callback. Panics when called on the dispatcher thread for the operation that is currently executing.

Source

pub fn wait_with_timeout( &self, timeout: Duration, ) -> Result<bool, OperationCanceledError>

Waits for this operation to complete, for at most timeout.

Returns Ok(true) when the operation completed in time, Ok(false) when it is still pending or executing after timeout, and Err when it was aborted.

On the dispatcher thread this pumps the queue like wait and measures the timeout with the dispatcher clock; a nested frame (background priorities, where the platform supports run loops) is left by a dispatcher timer. On any other thread it blocks. A zero timeout only reports the current state.

§Panics

Re-raises the panic of the callback. Panics when called on the dispatcher thread for the operation that is currently executing.

Source

pub fn result(&self) -> Result<R, OperationCanceledError>

Takes the result of the operation.

When the operation has not finished yet this blocks, which is only supported on non-dispatcher threads.

§Panics

Re-raises the panic of the callback. Panics when the operation is not finished and the calling thread is the dispatcher thread, when the result has already been taken, and when the result of a local operation is requested from another thread.

Trait Implementations§

Source§

impl<R> Clone for DispatcherOperation<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for DispatcherOperation<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R: 'static> Future for DispatcherOperation<R>

Source§

type Output = Result<R, OperationCanceledError>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations§

§

impl<R> Freeze for DispatcherOperation<R>
where PhantomData<fn() -> R>: Freeze,

§

impl<R> RefUnwindSafe for DispatcherOperation<R>
where PhantomData<fn() -> R>: RefUnwindSafe,

§

impl<R> Send for DispatcherOperation<R>
where PhantomData<fn() -> R>: Send,

§

impl<R> Sync for DispatcherOperation<R>
where PhantomData<fn() -> R>: Sync,

§

impl<R> Unpin for DispatcherOperation<R>
where PhantomData<fn() -> R>: Unpin,

§

impl<R> UnsafeUnpin for DispatcherOperation<R>
where PhantomData<fn() -> R>: UnsafeUnpin,

§

impl<R> UnwindSafe for DispatcherOperation<R>
where PhantomData<fn() -> R>: UnwindSafe,

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<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.