Enum spirit_tokio::Runtime [−][src]
pub enum Runtime { ThreadPool(Box<FnMut(&mut Builder) + Send>), CurrentThread(Box<FnMut(&mut Builder) + Send>), Custom(Box<FnMut(TokioBody) -> Result<(), Error> + Send>), // some variants omitted }
A helper to initialize a tokio runtime as part of spirit.
The helpers in this crate (TcpListen
,
UdpListen
) use this to make sure they have a runtime to handle the
sockets on.
If you prefer to specify configuration of the runtime to use, instead of the default one, you can create an instance of this helper yourself and register it before registering any socket helpers, which will take precedence and the sockets will use the one provided by you.
Note that the provided closures are FnMut
mostly because Box<FnOnce>
doesn't work. They
will be called just once, so you can use Option<T>
inside and consume the value by
take.unwrap()
.
Future compatibility
More options may be added into the enum at any time. Such change will not be considered a breaking change.
Examples
TODO: Something with registering it first and registering another helper later on.
Variants
ThreadPool(Box<FnMut(&mut Builder) + Send>)
Use the threadpool runtime.
The threadpool runtime is the default (both in tokio and spirit).
This allows you to modify the builder prior to starting it, specifying custom options.
CurrentThread(Box<FnMut(&mut Builder) + Send>)
Use the current thread runtime.
If you prefer to run everything in a single thread, use this variant. The provided closure can modify the builder prior to starting it.
Custom(Box<FnMut(TokioBody) -> Result<(), Error> + Send>)
Use completely custom runtime.
The provided closure should start the runtime and execute the provided future on it, blocking until the runtime becomes empty.
This allows combining arbitrary runtimes that are not directly supported by either tokio or spirit.
Trait Implementations
impl Default for Runtime
[src]
impl Default for Runtime
impl<S, O, C> Helper<S, O, C> for Runtime where
S: Borrow<ArcSwap<C>> + Sync + Send + 'static,
C: Deserialize<'de> + Send + Sync + 'static,
O: Debug + StructOpt + Sync + Send + 'static,
[src]
impl<S, O, C> Helper<S, O, C> for Runtime where
S: Borrow<ArcSwap<C>> + Sync + Send + 'static,
C: Deserialize<'de> + Send + Sync + 'static,
O: Debug + StructOpt + Sync + Send + 'static,