Skip to content

Commit

Permalink
fix: Don't require tokio rt-multi-thread feature (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs authored Sep 2, 2023
1 parent 4fc9c55 commit cf61e47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
22 changes: 1 addition & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion platforms/unix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ atspi = { version = "0.10.1", default-features = false }
futures-lite = "1.12.0"
once_cell = { version = "1.17.1", optional = true }
serde = "1.0"
tokio = { version = "1.10.0", optional = true, features = ["rt-multi-thread", "net", "time"] }
tokio = { version = "1.10.0", optional = true, features = ["rt", "net", "time"] }
zbus = { version = "3.6", default-features = false }

23 changes: 17 additions & 6 deletions platforms/unix/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ pub(crate) fn block_on<F: std::future::Future>(future: F) -> F::Output {
}

#[cfg(feature = "tokio")]
pub(crate) static TOKIO_RT: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.enable_io()
.enable_time()
pub(crate) static TOKIO_RT: Lazy<tokio::runtime::Handle> = Lazy::new(|| {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("launch of single-threaded tokio runtime")
.expect("create tokio runtime");
let handle = rt.handle().clone();
std::thread::Builder::new()
.name("accesskit-tokio".into())
.spawn(move || {
rt.block_on(async {
let duration = std::time::Duration::from_secs(86400);
loop {
tokio::time::sleep(duration).await;
}
});
})
.expect("launch tokio runtime thread");
handle
});

#[cfg(feature = "tokio")]
Expand Down

0 comments on commit cf61e47

Please sign in to comment.