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
Provides the equivalent of Runtime::new
.
A singlethreaded runtime.
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.
Tuple Fields of FromCfg
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.