#[cfg_attr(spawned_sim, allow(unused_imports, dead_code))]
mod tokio;
#[cfg(spawned_sim)]
pub mod sim;
#[cfg(all(spawned_sim, not(tokio_unstable)))]
compile_error!(
"--cfg spawned_sim needs --cfg tokio_unstable too: \
RUSTFLAGS=\"--cfg spawned_sim --cfg tokio_unstable\""
);
mod sim_test;
pub use sim_test::{sim_test, SimTest};
#[cfg(feature = "backend-experiments")]
mod dispatch_gate;
#[cfg(feature = "backend-experiments")]
#[doc(hidden)]
pub mod experimental;
use crate::tracing::init_tracing;
pub mod affinity;
#[cfg(spawned_sim)]
pub use crate::tasks::sim::{
block_in_place, sleep, spawn, spawn_blocking, task_id, timeout, unconstrained, yield_now,
Handle, JoinHandle, Runtime, RuntimeFlavor,
};
pub use crate::tasks::tokio::mpsc;
pub use crate::tasks::tokio::oneshot;
#[cfg(not(spawned_sim))]
pub use crate::tasks::tokio::sleep;
#[cfg(not(spawned_sim))]
pub use crate::tasks::tokio::timeout;
pub use crate::tasks::tokio::watch;
pub use crate::tasks::tokio::CancellationToken;
#[cfg(not(spawned_sim))]
pub use crate::tasks::tokio::{
block_in_place, spawn, spawn_blocking, task_id, unconstrained, yield_now, Handle, JoinHandle,
Runtime, RuntimeFlavor,
};
pub use crate::tasks::tokio::{BroadcastStream, ReceiverStream};
use std::future::Future;
#[cfg(not(spawned_sim))]
pub fn worker_runtime(name: &str, workers: usize) -> std::io::Result<Runtime> {
::tokio::runtime::Builder::new_multi_thread()
.worker_threads(workers)
.thread_name(name)
.enable_all()
.build()
}
#[cfg(not(spawned_sim))]
pub fn control_runtime() -> std::io::Result<Runtime> {
::tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
}
pub fn run<F: Future>(future: F) -> F::Output {
init_tracing();
let rt = Runtime::new().unwrap();
rt.block_on(future)
}
pub fn block_on<F: Future>(future: F) -> F::Output {
Handle::current().block_on(future)
}
#[cfg(spawned_sim)]
pub use crate::tasks::sim::ctrl_c;
#[cfg(not(spawned_sim))]
pub use crate::tasks::tokio::ctrl_c;
#[cfg(spawned_sim)]
pub fn worker_runtime(_name: &str, _workers: usize) -> std::io::Result<Runtime> {
Runtime::new()
}
#[cfg(spawned_sim)]
pub fn control_runtime() -> std::io::Result<Runtime> {
Runtime::new()
}