diff --git a/Cargo.toml b/Cargo.toml index 5144d83..d5b9d62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,13 +9,13 @@ identifier = "io.github.me.dynasty" icon = ["assets/dynasty.icns"] [dependencies] -binance-rs-async = { version = "1.3.2", default_features = false, features = ["rustls-tls", "wallet_api"] } +binance-rs-async = { version = "1.3.2", default-features = false, features = ["rustls-tls", "wallet_api"] } chrono = "0.4.31" iced = { version = "0.12.0", features = ["tokio", "debug", "lazy", "svg", "image", "advanced", "canvas"] } iced_futures = "0.12.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" -tokio = { version = "1.32.0", default-features = false, features=["sync"]} +tokio = { version = "1.32.0", default-features = false, features = ["sync", "time", "rt", "rt-multi-thread"]} ngnk = { path = "crates/ngnk", optional = true } meval = { version = "0.2.0", optional = true } plotters = "0.3.5" diff --git a/src/app.rs b/src/app.rs index 082d0da..ea6744b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -13,7 +13,6 @@ use std::env; use std::time::Duration; use binance::rest_model::KlineSummaries; -use iced::executor; use iced::font; use iced::widget::button; use iced::widget::scrollable; @@ -96,7 +95,7 @@ impl Application for App { type Message = Message; type Theme = Theme; type Flags = Config; - type Executor = executor::Default; + type Executor = crate::executor::DynastyExecutor; fn new(flags: Self::Flags) -> (Self, Command) { let app = App::new(flags); diff --git a/src/executor.rs b/src/executor.rs new file mode 100644 index 0000000..8817487 --- /dev/null +++ b/src/executor.rs @@ -0,0 +1,27 @@ +use std::future::Future; + +use iced::Executor; +use iced_futures::futures; + +pub(crate) struct DynastyExecutor(tokio::runtime::Runtime); + +/// Customized iced_futures tokio executor +impl Executor for DynastyExecutor { + fn new() -> Result { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .thread_name("dynasty-tokio") + .build() + .map(Self) + } + + #[allow(clippy::let_underscore_future)] + fn spawn(&self, future: impl Future + Send + 'static) { + let _ = tokio::runtime::Runtime::spawn(&self.0, future); + } + + fn enter(&self, f: impl FnOnce() -> R) -> R { + let _guard = tokio::runtime::Runtime::enter(&self.0); + f() + } +} diff --git a/src/main.rs b/src/main.rs index 2181b51..b00110c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod api; mod app; mod config; mod data; +mod executor; mod message; mod svg_logos; mod theme;