mqtt_async_client/util/
tokio_runtime.rs1use std::future::Future;
2use tokio::{
3 self,
4 task::JoinHandle
5};
6
7#[derive(Clone, Debug)]
9pub enum TokioRuntime {
10 Default,
12
13 Handle(tokio::runtime::Handle),
15}
16
17impl TokioRuntime {
18 pub fn spawn<F>(&self, f: F) -> JoinHandle<F::Output>
20 where
21 F: Future + Send + 'static,
22 F::Output: Send + 'static, {
23 match self {
24 TokioRuntime::Default => tokio::spawn(f),
25 TokioRuntime::Handle(h) => h.spawn(f),
26 }
27 }
28}
29
30impl Default for TokioRuntime {
31 fn default() -> TokioRuntime {
32 TokioRuntime::Default
33 }
34}