[][src]Enum spirit_tokio::runtime::Tokio

#[non_exhaustive]pub enum Tokio<O, C> {
    Default,
    SingleThreaded,
    Custom(Box<dyn FnMut(&O, &Arc<C>) -> Result<Runtime, AnyError> + Send>),
    FromCfg(Box<dyn FnMut(&O, &C) -> Config + Send>, Box<dyn FnMut(Builder) -> Result<Runtime, AnyError> + Send>),
}

A spirit Extension to inject a tokio runtime.

This, when inserted into spirit Builder with the with_singleton will provide the application with a tokio runtime.

This will:

  • Run the application body inside the runtime (to allow spawning tasks and creating tokio resources).
  • Run the configuration/termination/signal hooks inside the async context of the runtime (for similar reasons).
  • Keep the runtime running until terminate is invoked (either explicitly or by CTRL+C or similar).

A default instance (Tokio::Default) is inserted by pipelines containing the FutureInstaller.

Variants (Non-exhaustive)

Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Default

Provides the equivalent of Runtime::new.

SingleThreaded

A singlethreaded runtime.

Custom(Box<dyn FnMut(&O, &Arc<C>) -> Result<Runtime, AnyError> + Send>)

Allows the caller to provide arbitrary constructor for the Runtime.

This variant also allows creating the basic (non-threaded) scheduler if needed. Note that some operations with such runtime are prone to cause deadlocks.

FromCfg(Box<dyn FnMut(&O, &C) -> Config + Send>, Box<dyn FnMut(Builder) -> Result<Runtime, AnyError> + Send>)

Uses configuration for constructing the Runtime.

This'll use the extractor (the first closure) to get a Config, create a Builder based on that. It'll explicitly enable all the drivers and enable threaded runtime. Then it calls the postprocessor (the second closure) to turn it into the Runtime.

This is the more general form. If you're fine with just basing it on the configuration without much tweaking, you can use Tokio::from_cfg (which will create this variant with reasonable value of preprocessor).

This is available only with the [rt-from-cfg] feature enabled.

Implementations

impl<O, C> Tokio<O, C>[src]

pub fn from_cfg<E>(mut extractor: E) -> Self where
    E: FnMut(&C) -> Config + Send + 'static, 
[src]

Simplified construction from configuration.

This is similar to Tokio::FromCfg. However, the extractor takes only the configuration structure, not the command line options. Furthermore, post-processing is simply calling Builder::build, without a chance to tweak.

pub fn create(&mut self, opts: &O, cfg: &Arc<C>) -> Result<Runtime, AnyError>[src]

Method to create the runtime.

This can be used when not taking advantage of the spirit auto-management features.

Trait Implementations

impl<O, C> Default for Tokio<O, C>[src]

impl<E> Extension<E> for Tokio<E::Opts, E::Config> where
    E: Extensible<Ok = E>,
    E::Config: DeserializeOwned + Send + Sync + 'static,
    E::Opts: StructOpt + Send + Sync + 'static, 
[src]

Auto Trait Implementations

impl<O, C> !RefUnwindSafe for Tokio<O, C>[src]

impl<O, C> Send for Tokio<O, C>[src]

impl<O, C> !Sync for Tokio<O, C>[src]

impl<O, C> Unpin for Tokio<O, C>[src]

impl<O, C> !UnwindSafe for Tokio<O, C>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoResult<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.