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

#[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>),
}
Expand description

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)

This enum is marked as 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.

Tuple Fields of Custom

0: 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>)

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.

Tuple Fields of FromCfg

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

Implementations

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.

Method to create the runtime.

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

Trait Implementations

Returns the “default value” for a type. Read more

Perform the transformation on the given extensible. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Turns self into the result.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.