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: From<Status>>(
&self,
f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>,
) -> Result<R, E> { ... }
fn spawn_task(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<(), Status>
where Self: 'static { ... }
fn after_deadline(&self, deadline: MonotonicInstant) -> AfterDeadline<Self> ⓘ { ... }
}Expand description
A trait that can be used to access a lifetime-constrained dispatcher in a generic way.
Required Methods§
Sourcefn 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.
Provided Methods§
Sourcefn on_maybe_dispatcher<R, E: From<Status>>(
&self,
f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>,
) -> Result<R, E>
fn on_maybe_dispatcher<R, E: From<Status>>( &self, f: impl FnOnce(AsyncDispatcherRef<'_>) -> Result<R, E>, ) -> Result<R, E>
Helper version of OnDispatcher::on_dispatcher that translates an invalidated dispatcher
handle into a [Status::BAD_STATE] error instead of giving the callback None.
Sourcefn spawn_task(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<(), Status>where
Self: 'static,
fn spawn_task(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> Result<(), 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.
Sourcefn after_deadline(&self, deadline: MonotonicInstant) -> AfterDeadline<Self> ⓘ
fn after_deadline(&self, deadline: MonotonicInstant) -> 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.