Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom executor #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Message>) {
let app = App::new(flags);
Expand Down
27 changes: 27 additions & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
@@ -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<Self, futures::io::Error> {
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<Output = ()> + Send + 'static) {
let _ = tokio::runtime::Runtime::spawn(&self.0, future);
}

fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
let _guard = tokio::runtime::Runtime::enter(&self.0);
f()
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod api;
mod app;
mod config;
mod data;
mod executor;
mod message;
mod svg_logos;
mod theme;
Expand Down