Skip to main content

Reactor

Struct Reactor 

Source
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>
where Ctx: Send + 'static, T: Task<Ctx> + Send + 'static,

Source

pub fn new_current() -> Result<Self>

Build a reactor on a freshly created current_thread runtime.

Source

pub fn new(runtime: Option<Arc<Runtime>>) -> Result<Self>

Build a reactor. Supply Some(rt) to reuse an existing runtime.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn shutdown(self) -> Result<()>

Close the control channel and join the background thread.

Trait Implementations§

Source§

impl<Ctx, T> Drop for Reactor<Ctx, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<Ctx, T> !RefUnwindSafe for Reactor<Ctx, T>

§

impl<Ctx, T> !UnwindSafe for Reactor<Ctx, T>

§

impl<Ctx, T> Freeze for Reactor<Ctx, T>
where PhantomData<fn(Ctx, T)>: Freeze,

§

impl<Ctx, T> Send for Reactor<Ctx, T>
where PhantomData<fn(Ctx, T)>: Send,

§

impl<Ctx, T> Sync for Reactor<Ctx, T>
where PhantomData<fn(Ctx, T)>: Sync,

§

impl<Ctx, T> Unpin for Reactor<Ctx, T>
where PhantomData<fn(Ctx, T)>: Unpin,

§

impl<Ctx, T> UnsafeUnpin for Reactor<Ctx, T>
where PhantomData<fn(Ctx, T)>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.