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>
impl<R: 'static> DispatcherOperation<R>
Sourcepub fn status(&self) -> DispatcherOperationStatus
pub fn status(&self) -> DispatcherOperationStatus
The current status of the operation.
Sourcepub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ
pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ
The dispatcher the operation was queued on.
pub fn priority(&self) -> DispatcherPriority
Sourcepub fn set_priority(&self, value: DispatcherPriority)
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.
Sourcepub fn aborted(
&self,
handler: impl Fn() + Send + Sync + 'static,
) -> Rc<dyn IDisposable>
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.
Sourcepub fn completed(
&self,
handler: impl Fn() + Send + Sync + 'static,
) -> Rc<dyn IDisposable>
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.
Sourcepub fn abort(&self) -> bool
pub fn abort(&self) -> bool
Removes a pending operation from the queue. Returns false when the
operation is no longer pending.
Sourcepub fn wait(&self) -> Result<(), OperationCanceledError>
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.
Sourcepub fn wait_with_timeout(
&self,
timeout: Duration,
) -> Result<bool, OperationCanceledError>
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.
Sourcepub fn result(&self) -> Result<R, OperationCanceledError>
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>
impl<R> Clone for DispatcherOperation<R>
Source§impl<R> Debug for DispatcherOperation<R>
impl<R> Debug for DispatcherOperation<R>
Source§impl<R: 'static> Future for DispatcherOperation<R>
impl<R: 'static> Future for DispatcherOperation<R>
Source§type Output = Result<R, OperationCanceledError>
type Output = Result<R, OperationCanceledError>
Auto Trait Implementations§
impl<R> Freeze for DispatcherOperation<R>
impl<R> RefUnwindSafe for DispatcherOperation<R>
impl<R> Send for DispatcherOperation<R>
impl<R> Sync for DispatcherOperation<R>
impl<R> Unpin for DispatcherOperation<R>
impl<R> UnsafeUnpin for DispatcherOperation<R>
impl<R> UnwindSafe for DispatcherOperation<R>
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
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more