pub struct SchedulerLocalExecutor { /* private fields */ }Expand description
A !Send executor pinned to a single session. Tasks spawned on it run in
order on whichever thread drains the dispatch destination supplied at
construction time — typically the main thread for the default session, or
a dedicated OS thread for sessions created by spawn_dedicated_thread.
Implementations§
Source§impl LocalExecutor
impl LocalExecutor
Sourcepub fn new(
session_id: SessionId,
scheduler: Arc<dyn Scheduler>,
dispatch: impl Fn(Runnable<RunnableMeta>) + Send + Sync + 'static,
) -> LocalExecutor
pub fn new( session_id: SessionId, scheduler: Arc<dyn Scheduler>, dispatch: impl Fn(Runnable<RunnableMeta>) + Send + Sync + 'static, ) -> LocalExecutor
Constructs a local executor that runs spawned tasks by sending their
runnables through dispatch. The scheduler is retained for access to
clocks, timers, and other scheduler-level services.
For the common case of routing runnables through
Scheduler::schedule_local, callers pass a closure that does exactly
that. spawn_dedicated_thread instead passes a closure that sends to
the dedicated thread’s channel.
pub fn session_id(&self) -> SessionId
pub fn scheduler(&self) -> &Arc<dyn Scheduler> ⓘ
pub fn spawn<F>(&self, future: F) -> Task<<F as Future>::Output> ⓘ
pub fn block_on<Fut>(&self, future: Fut) -> <Fut as Future>::Outputwhere
Fut: Future,
Sourcepub fn block_with_timeout<Fut>(
&self,
timeout: Duration,
future: Fut,
) -> Result<<Fut as Future>::Output, impl Future<Output = <Fut as Future>::Output> + use<Fut>>where
Fut: Future,
pub fn block_with_timeout<Fut>(
&self,
timeout: Duration,
future: Fut,
) -> Result<<Fut as Future>::Output, impl Future<Output = <Fut as Future>::Output> + use<Fut>>where
Fut: Future,
Block until the future completes or timeout occurs. Returns Ok(output) if completed, Err(future) if timed out.
pub fn timer(&self, duration: Duration) -> Timer
pub fn now(&self) -> Instant
Sourcepub fn spawn_dedicated<F, Fut>(&self, f: F) -> Task<<Fut as Future>::Output> ⓘ
pub fn spawn_dedicated<F, Fut>(&self, f: F) -> Task<<Fut as Future>::Output> ⓘ
Spawn a closure on a fresh session pinned to its own LocalExecutor.
The closure runs on a new OS thread under PlatformScheduler, or on
the test scheduler’s loop under TestScheduler.
The returned Task represents the dedicated work: dropping it cancels
the dedicated closure, .awaiting it yields the closure’s return
value, .detach()ing it lets the dedicated work run independently of
the caller.
Trait Implementations§
Source§impl Clone for LocalExecutor
impl Clone for LocalExecutor
Source§fn clone(&self) -> LocalExecutor
fn clone(&self) -> LocalExecutor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LocalExecutor
impl !Send for LocalExecutor
impl !Sync for LocalExecutor
impl !UnwindSafe for LocalExecutor
impl Freeze for LocalExecutor
impl Unpin for LocalExecutor
impl UnsafeUnpin for LocalExecutor
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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