spawned_rt/tasks/
mod.rs

1//! Runtime wrapper to remove dependencies from code. Using this library will
2//! allow to set a tokio runtime or any other runtime, once implemented just by
3//! changing the enabled feature.
4//! May implement the `deterministic` version based on comonware.xyz's runtime:
5//! https://github.com/commonwarexyz/monorepo/blob/main/runtime/src/deterministic.rs
6//!
7//! Currently, only a very limited set of tokio functionality is reexported. We may want to
8//! extend this functionality as needed.
9
10mod tokio;
11
12use ::tokio::runtime::Handle;
13
14use crate::tracing::init_tracing;
15
16pub use crate::tasks::tokio::mpsc;
17pub use crate::tasks::tokio::oneshot;
18pub use crate::tasks::tokio::sleep;
19pub use crate::tasks::tokio::timeout;
20pub use crate::tasks::tokio::CancellationToken;
21pub use crate::tasks::tokio::{spawn, spawn_blocking, task_id, JoinHandle, Runtime};
22pub use crate::tasks::tokio::{BroadcastStream, ReceiverStream};
23use std::future::Future;
24
25pub fn run<F: Future>(future: F) -> F::Output {
26    init_tracing();
27
28    let rt = Runtime::new().unwrap();
29    rt.block_on(future)
30}
31
32pub fn block_on<F: Future>(future: F) -> F::Output {
33    Handle::current().block_on(future)
34}