From 1da003dc2874bed0a3ce341699b7393c3dcd3ebd Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 5 Dec 2024 03:16:50 +0100 Subject: [PATCH] feat: allow multi-thread worker with feature flag --- Cargo.toml | 1 + src/main.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0e79478..6531cb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ async-recursion = "1.1.1" [features] default = [] bundled = ["rusqlite/bundled"] +multi-thread = ["tokio/rt-multi-thread", "tokio/time"] diff --git a/src/main.rs b/src/main.rs index 07e125e..dbc8c85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,19 @@ fn main() { }, }; - if let Err(e) = tokio::runtime::Builder::new_current_thread() + let mut runtime_builder = { + #[cfg(feature = "multi-thread")] + { + tokio::runtime::Builder::new_multi_thread() + } + + #[cfg(not(feature = "multi-thread"))] + { + tokio::runtime::Builder::new_current_thread() + } + }; + + if let Err(e) = runtime_builder .enable_all() .build() .expect("could not create tokio runtime")