pub struct Runtime(/* private fields */);Expand description
A cheaply cloneable handle to the runtime resources.
Wraps an Arc<RuntimeInner> and provides access to:
- The tokio [
Handle] - Task spawning with shutdown awareness and panic monitoring
- Rayon thread pools (with
rayonfeature)
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn take_task_manager_handle(
&self,
) -> Option<JoinHandle<Result<(), PanickedTaskError>>>
pub fn take_task_manager_handle( &self, ) -> Option<JoinHandle<Result<(), PanickedTaskError>>>
Takes the TaskManager handle out of this runtime, if one is stored.
The handle resolves with Err(PanickedTaskError) if a critical task panicked,
or Ok(()) if shutdown was requested. If not taken, the background task still
runs and logs panics at debug! level.
Sourcepub fn cpu_pool(&self) -> &ThreadPool
Available on crate feature rayon only.
pub fn cpu_pool(&self) -> &ThreadPool
rayon only.Get the general-purpose rayon CPU thread pool.
Sourcepub fn rpc_pool(&self) -> &BlockingTaskPool
Available on crate feature rayon only.
pub fn rpc_pool(&self) -> &BlockingTaskPool
rayon only.Get the RPC blocking task pool.
Sourcepub fn storage_pool(&self) -> &ThreadPool
Available on crate feature rayon only.
pub fn storage_pool(&self) -> &ThreadPool
rayon only.Get the storage I/O pool.
Sourcepub fn blocking_guard(&self) -> BlockingTaskGuard
Available on crate feature rayon only.
pub fn blocking_guard(&self) -> BlockingTaskGuard
rayon only.Get a clone of the BlockingTaskGuard.
Sourcepub fn proof_storage_worker_pool(&self) -> &WorkerPool
Available on crate feature rayon only.
pub fn proof_storage_worker_pool(&self) -> &WorkerPool
rayon only.Get the proof storage worker pool.
Sourcepub fn proof_account_worker_pool(&self) -> &WorkerPool
Available on crate feature rayon only.
pub fn proof_account_worker_pool(&self) -> &WorkerPool
rayon only.Get the proof account worker pool.
Sourcepub fn prewarming_pool(&self) -> &WorkerPool
Available on crate feature rayon only.
pub fn prewarming_pool(&self) -> &WorkerPool
rayon only.Get the prewarming pool.
Source§impl Runtime
impl Runtime
Sourcepub fn on_shutdown_signal(&self) -> &Shutdown ⓘ
pub fn on_shutdown_signal(&self) -> &Shutdown ⓘ
Returns the receiver of the shutdown signal.
Sourcepub fn spawn_task<F>(&self, fut: F) -> JoinHandle<()>
pub fn spawn_task<F>(&self, fut: F) -> JoinHandle<()>
Spawns the task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn].
Sourcepub fn spawn_blocking_task<F>(&self, fut: F) -> JoinHandle<()>
pub fn spawn_blocking_task<F>(&self, fut: F) -> JoinHandle<()>
Spawns a blocking task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn_blocking].
Sourcepub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
Spawns a blocking closure directly on the tokio runtime, bypassing shutdown awareness. Useful for raw CPU-bound work.
Sourcepub fn spawn_blocking_named<F, R>(
&self,
name: &'static str,
func: F,
) -> LazyHandle<R>
pub fn spawn_blocking_named<F, R>( &self, name: &'static str, func: F, ) -> LazyHandle<R>
Spawns a blocking closure on a dedicated, named OS thread.
Unlike spawn_blocking which uses tokio’s blocking thread pool,
this reuses the same OS thread for all tasks submitted under the same name. The thread
is created lazily on first use and its OS thread name is set to name.
This is useful for tasks that benefit from running on a stable thread, e.g. for thread-local state reuse or to avoid thread creation overhead on hot paths.
Returns a LazyHandle handle that resolves on first access and caches
the result.
Sourcepub fn spawn_with_signal<F>(
&self,
f: impl FnOnce(Shutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_with_signal<F>( &self, f: impl FnOnce(Shutdown) -> F, ) -> JoinHandle<()>
Spawns the task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn].
Sourcepub fn spawn_critical_task<F>(
&self,
name: &'static str,
fut: F,
) -> JoinHandle<()>
pub fn spawn_critical_task<F>( &self, name: &'static str, fut: F, ) -> JoinHandle<()>
This spawns a critical task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
If this task panics, the TaskManager is notified.
Sourcepub fn spawn_critical_blocking_task<F>(
&self,
name: &'static str,
fut: F,
) -> JoinHandle<()>
pub fn spawn_critical_blocking_task<F>( &self, name: &'static str, fut: F, ) -> JoinHandle<()>
This spawns a critical blocking task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
If this task panics, the TaskManager is notified.
Sourcepub fn spawn_critical_with_shutdown_signal<F>(
&self,
name: &'static str,
f: impl FnOnce(Shutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_critical_with_shutdown_signal<F>( &self, name: &'static str, f: impl FnOnce(Shutdown) -> F, ) -> JoinHandle<()>
This spawns a critical task onto the runtime.
If this task panics, the TaskManager is notified.
Sourcepub fn spawn_critical_with_graceful_shutdown_signal<F>(
&self,
name: &'static str,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_critical_with_graceful_shutdown_signal<F>( &self, name: &'static str, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
This spawns a critical task onto the runtime.
If this task panics, the TaskManager is notified.
The TaskManager will wait until the given future has completed before shutting down.
§Example
executor.spawn_critical_with_graceful_shutdown_signal("grace", async move |shutdown| {
// await the shutdown signal
let guard = shutdown.await;
// do work before exiting the program
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// allow graceful shutdown
drop(guard);
});Sourcepub fn spawn_with_graceful_shutdown_signal<F>(
&self,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_with_graceful_shutdown_signal<F>( &self, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
This spawns a regular task onto the runtime.
The TaskManager will wait until the given future has completed before shutting down.
§Example
executor.spawn_with_graceful_shutdown_signal(async move |shutdown| {
// await the shutdown signal
let guard = shutdown.await;
// do work before exiting the program
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// allow graceful shutdown
drop(guard);
});Sourcepub fn initiate_graceful_shutdown(
&self,
) -> Result<GracefulShutdown, SendError<()>>
pub fn initiate_graceful_shutdown( &self, ) -> Result<GracefulShutdown, SendError<()>>
Sends a request to the TaskManager to initiate a graceful shutdown.
Caution: This will terminate the entire program.
Sourcepub fn graceful_shutdown(&self)
pub fn graceful_shutdown(&self)
Fires the shutdown signal and waits until all graceful tasks complete.
Sourcepub fn graceful_shutdown_with_timeout(&self, timeout: Duration) -> bool
pub fn graceful_shutdown_with_timeout(&self, timeout: Duration) -> bool
Fires the shutdown signal and waits until all graceful tasks complete or the timeout elapses.
Returns true if all tasks completed before the timeout.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes