pub trait Runtime:
Send
+ Sync
+ 'static {
// Required methods
fn spawn(&self, task: BoxFuture<'static, ()>);
fn sleep(&self, duration: Duration) -> BoxFuture<'static, ()>;
// Provided methods
fn defer(&self, task: BoxFuture<'static, ()>) { ... }
fn spawn_blocking(
&self,
task: Box<dyn FnOnce() + Send + 'static>,
) -> Result<(), BoxError> { ... }
}Expand description
Runs detached work the cache does not await and supplies its timers.
Detached work is raw source or adapter work that outlives a caller’s deadline, and shadow validation jobs. Timers deliver deadlines; a controlled runtime may deliver them on its own schedule.
Required Methods§
Provided Methods§
Sourcefn defer(&self, task: BoxFuture<'static, ()>)
fn defer(&self, task: BoxFuture<'static, ()>)
Start task after work that is already runnable has progressed.
Production runtimes treat this like Runtime::spawn. A controlled
test runtime runs deferred work only once everything else is blocked.
Sourcefn spawn_blocking(
&self,
task: Box<dyn FnOnce() + Send + 'static>,
) -> Result<(), BoxError>
fn spawn_blocking( &self, task: Box<dyn FnOnce() + Send + 'static>, ) -> Result<(), BoxError>
Admit synchronous CPU work without blocking the async executor.
The default uses a process-wide pool of two threads and two queued jobs. A full queue or thread-creation failure returns an error; cache plumbing fails open. Once admitted, a job owns its resources until execution or destruction, independently of the future waiting for its result. Custom runtimes may override this with their own bounded CPU executor. A controlled test runtime may queue the job for deterministic execution.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Runtime for StepRuntime
impl Runtime for TokioRuntime
tokio only.