pub trait Spawn:
Send
+ Sync
+ 'static {
// Required methods
fn spawn(&self, fut: BoxFuture<'static, ()>) -> TaskHandle ⓘ;
fn try_spawn(
&self,
fut: BoxFuture<'static, ()>,
) -> Result<TaskHandle, Refused>;
// Provided method
fn name(&self) -> &'static str { ... }
}Required Methods§
Sourcefn spawn(&self, fut: BoxFuture<'static, ()>) -> TaskHandle ⓘ
fn spawn(&self, fut: BoxFuture<'static, ()>) -> TaskHandle ⓘ
Starts fut as a task of its own. The task runs whether the handle is kept or not:
dropping the handle detaches it. An implementation builds the handle with
TaskHandle::launch, which is what makes a panic end the task as TaskEnd::Panicked.
A runtime that has shut down drops fut unrun, without panicking, and the handle answers
TaskEnd::Aborted; try_spawn tells that refusal from an abort.
Sourcefn try_spawn(&self, fut: BoxFuture<'static, ()>) -> Result<TaskHandle, Refused>
fn try_spawn(&self, fut: BoxFuture<'static, ()>) -> Result<TaskHandle, Refused>
spawn, answering Err(Refused) when the runtime has shut down. Refused: the task was not
started, or a shutdown stopped it before it finished. fut may have been polled, so a
refusal is no proof that none of its work ran. A runtime that cannot shut down answers
spawn’s handle as Ok. A wrapper forwards this to the runtime it wraps, as it forwards
spawn: answering Ok there drops that runtime’s refusal.
Provided Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
The runtime’s name, which an integration that supports one runtime reads to refuse the
others at connect rather than look a runtime up from the thread. ulo-runtime-tokio
answers "tokio" and ulo-runtime-smol "smol". A runtime that answers nothing of its
own is "unknown", which such an integration refuses as it refuses any name it does not
support.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".