Trait OnDispatcher
pub trait OnDispatcher:
Clone
+ Send
+ Sync {
// Required method
fn on_dispatcher<R>(
&self,
f: impl FnOnce(Option<AsyncDispatcherRef<'_>>) -> R,
) -> R;
// Provided methods
fn on_maybe_dispatcher<R, E>(
&self,
f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>,
) -> Result<R, E>
where E: From<Status> { ... }
fn spawn(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<JoinHandle<()>, Status>
where Self: 'static { ... }
fn compute<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> Task<T> ⓘ
where T: Send + 'static,
Self: 'static { ... }
fn after_deadline(
&self,
deadline: Instant<MonotonicTimeline>,
) -> AfterDeadline<Self> ⓘ { ... }
}Expand description
A trait that can be used to access a lifetime-constrained dispatcher in a generic way.
Required Methods§
fn on_dispatcher<R>(
&self,
f: impl FnOnce(Option<AsyncDispatcherRef<'_>>) -> R,
) -> R
fn on_dispatcher<R>( &self, f: impl FnOnce(Option<AsyncDispatcherRef<'_>>) -> R, ) -> R
Runs the function f with a lifetime-bound AsyncDispatcherRef for this object’s dispatcher.
If the dispatcher is no longer valid, the callback will be given None.
Note that it is very important that no blocking work be done in this callback to prevent long lived strong references to dispatchers that might be shutting down.
Provided Methods§
fn on_maybe_dispatcher<R, E>(
&self,
f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>,
) -> Result<R, E>where
E: From<Status>,
fn on_maybe_dispatcher<R, E>(
&self,
f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>,
) -> Result<R, E>where
E: From<Status>,
Helper version of OnDispatcher::on_dispatcher that translates an invalidated dispatcher
handle into a [Status::BAD_STATE] error instead of giving the callback None.
Note that it is very important that no blocking work be done in this callback to prevent long lived strong references to dispatchers that might be shutting down.
fn spawn(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<JoinHandle<()>, Status>where
Self: 'static,
fn spawn(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<JoinHandle<()>, Status>where
Self: 'static,
Spawn an asynchronous task on this dispatcher. If this returns Ok then the task has
successfully been scheduled and will run or be cancelled and dropped when the dispatcher
shuts down. The returned future’s result will be Ok if the future completed
successfully, or an Err if the task did not complete for some reason (like the
dispatcher shut down).
Returns a JoinHandle that will detach the future when dropped.
fn compute<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> Task<T> ⓘwhere
T: Send + 'static,
Self: 'static,
fn compute<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> Task<T> ⓘwhere
T: Send + 'static,
Self: 'static,
Spawn an asynchronous task that outputs type ‘T’ on this dispatcher. The returned future’s
result will be Ok if the task was started and completed successfully, or an Err if
the task couldn’t be started or failed to complete (for example because the dispatcher was
shutting down).
Returns a Task that will cancel the future when dropped.
fn after_deadline(
&self,
deadline: Instant<MonotonicTimeline>,
) -> AfterDeadline<Self> ⓘ
fn after_deadline( &self, deadline: Instant<MonotonicTimeline>, ) -> AfterDeadline<Self> ⓘ
Returns a future that will fire when after the given deadline time.
This can be used instead of the fuchsia-async timer primitives in situations where there isn’t a currently active fuchsia-async executor running on that dispatcher for some reason (ie. the rust code does not own the dispatcher) or for cases where the small overhead of fuchsia-async compatibility is too much.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.