pub struct Reactor<Ctx, T> { /* private fields */ }Expand description
Owns the background thread running the tokio runtime + LocalSet.
§Shutdown
Dropping the reactor (or calling shutdown) closes the
spawn control channel and joins the background thread. The background
thread only exits once every TaskHandler clone has been dropped.
If producers are still alive, Drop/shutdown will block.
Implementations§
Source§impl<Ctx, T> Reactor<Ctx, T>
impl<Ctx, T> Reactor<Ctx, T>
Sourcepub fn new_current() -> Result<Self>
pub fn new_current() -> Result<Self>
Build a reactor on a freshly created current_thread runtime.
Sourcepub fn new(runtime: Option<Arc<Runtime>>) -> Result<Self>
pub fn new(runtime: Option<Arc<Runtime>>) -> Result<Self>
Build a reactor. Supply Some(rt) to reuse an existing runtime.
Sourcepub fn spawn(
&self,
task: T,
builder: TaskBuilder<Ctx>,
) -> Result<TaskHandler<Ctx>, SpawnError>
pub fn spawn( &self, task: T, builder: TaskBuilder<Ctx>, ) -> Result<TaskHandler<Ctx>, SpawnError>
Spawn a task using the default scheduler (FairPriority with
budget 16).
Blocks the current thread until the task has been started. Do not
call this from inside a tokio runtime; use spawn_async
instead.
Sourcepub fn spawn_with<S>(
&self,
task: T,
builder: TaskBuilder<Ctx>,
scheduler: S,
) -> Result<TaskHandler<Ctx>, SpawnError>where
S: Scheduler<Ctx>,
pub fn spawn_with<S>(
&self,
task: T,
builder: TaskBuilder<Ctx>,
scheduler: S,
) -> Result<TaskHandler<Ctx>, SpawnError>where
S: Scheduler<Ctx>,
Spawn a task with a user-supplied scheduler (blocking).
Sourcepub async fn spawn_async(
&self,
task: T,
builder: TaskBuilder<Ctx>,
) -> Result<TaskHandler<Ctx>, SpawnError>
pub async fn spawn_async( &self, task: T, builder: TaskBuilder<Ctx>, ) -> Result<TaskHandler<Ctx>, SpawnError>
Async version of spawn. Use this from inside a
tokio runtime.
Sourcepub async fn spawn_with_async<S>(
&self,
task: T,
builder: TaskBuilder<Ctx>,
scheduler: S,
) -> Result<TaskHandler<Ctx>, SpawnError>where
S: Scheduler<Ctx>,
pub async fn spawn_with_async<S>(
&self,
task: T,
builder: TaskBuilder<Ctx>,
scheduler: S,
) -> Result<TaskHandler<Ctx>, SpawnError>where
S: Scheduler<Ctx>,
Async version of spawn_with.