From 06b3b1417491771b16b98d1b637e305810980dc0 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 11:59:07 +0100 Subject: [PATCH 01/12] wip, allow to run tokio based futures in the bastion executor --- src/bastion-executor/Cargo.toml | 8 ++- src/bastion-executor/src/blocking.rs | 51 ++++++++++++++++- src/bastion-executor/src/pool.rs | 52 ++++++++++++++++- src/bastion-executor/src/run.rs | 2 +- src/bastion/Cargo.toml | 14 +++-- src/bastion/examples/hello_tokio.rs | 83 ++++++++++++++++++++++++++++ 6 files changed, 198 insertions(+), 12 deletions(-) create mode 100644 src/bastion/examples/hello_tokio.rs diff --git a/src/bastion-executor/Cargo.toml b/src/bastion-executor/Cargo.toml index d77975ee..fd25cce2 100644 --- a/src/bastion-executor/Cargo.toml +++ b/src/bastion-executor/Cargo.toml @@ -26,11 +26,12 @@ maintenance = { status = "actively-developed" } [features] unstable = [] +runtime-tokio = ["tokio"] [dependencies] -lightproc = "0.3.5" +# lightproc = "0.3.5" bastion-utils = "0.3.2" -# lightproc = { path = "../lightproc" } +lightproc = { path = "../lightproc" } # bastion-utils = { path = "../bastion-utils" } crossbeam-utils = "0.8" @@ -49,6 +50,9 @@ lever = "0.1.1-alpha.11" tracing = "0.1.19" crossbeam-queue = "0.3.0" +# Feature tokio +tokio = {version = "1.1", features = ["rt", "rt-multi-thread"], optional = true } + [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "^0.3.8", features = ["basetsd"] } diff --git a/src/bastion-executor/src/blocking.rs b/src/bastion-executor/src/blocking.rs index 6ecf49ad..6a761885 100644 --- a/src/bastion-executor/src/blocking.rs +++ b/src/bastion-executor/src/blocking.rs @@ -16,6 +16,8 @@ use std::iter::Iterator; use std::sync::Arc; use std::time::Duration; use std::{env, thread}; +#[cfg(feature = "runtime-tokio")] +use tokio::runtime; use tracing::trace; /// If low watermark isn't configured this is the default scaler value. @@ -41,6 +43,51 @@ struct BlockingRunner {} impl DynamicRunner for BlockingRunner { fn run_static(&self, park_timeout: Duration) -> ! { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("static thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._static_loop(park_timeout) }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._static_loop(park_timeout) + } + } + fn run_dynamic(&self, parker: &dyn Fn()) -> ! { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("dynamic thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._dynamic_loop(parker) }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._dynamic_loop(parker) + } + } + fn run_standalone(&self) { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("standalone thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._standalone() }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._standalone() + } + } +} + +impl BlockingRunner { + fn _static_loop(&self, park_timeout: Duration) -> ! { loop { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { trace!("static thread: running task"); @@ -51,7 +98,7 @@ impl DynamicRunner for BlockingRunner { thread::park_timeout(park_timeout); } } - fn run_dynamic(&self, parker: &dyn Fn()) -> ! { + fn _dynamic_loop(&self, parker: &dyn Fn()) -> ! { loop { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { trace!("dynamic thread: running task"); @@ -64,7 +111,7 @@ impl DynamicRunner for BlockingRunner { parker(); } } - fn run_standalone(&self) { + fn _standalone(&self) { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { task.run(); } diff --git a/src/bastion-executor/src/pool.rs b/src/bastion-executor/src/pool.rs index d4750e59..8b591d45 100644 --- a/src/bastion-executor/src/pool.rs +++ b/src/bastion-executor/src/pool.rs @@ -17,6 +17,8 @@ use std::iter::Iterator; use std::sync::Arc; use std::time::Duration; use std::{env, thread}; +#[cfg(feature = "runtime-tokio")] +use tokio::runtime; use tracing::trace; /// @@ -138,6 +140,52 @@ struct AsyncRunner {} impl DynamicRunner for AsyncRunner { fn run_static(&self, park_timeout: Duration) -> ! { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("static thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._static_loop(park_timeout) }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._static_loop(park_timeout) + } + } + fn run_dynamic(&self, parker: &dyn Fn()) -> ! { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("dynamic thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._dynamic_loop(parker) }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._dynamic_loop(parker) + } + } + fn run_standalone(&self) { + #[cfg(feature = "runtime-tokio")] + { + let thread_runtime = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("standalone thread: couldn't spawn tokio runtime"); + thread_runtime.block_on(async move { self._standalone() }) + } + #[cfg(not(feature = "runtime-tokio"))] + { + self._standalone() + } + self._standalone() + } +} + +impl AsyncRunner { + fn _static_loop(&self, park_timeout: Duration) -> ! { loop { for task in &POOL.receiver { trace!("static: running task"); @@ -148,7 +196,7 @@ impl DynamicRunner for AsyncRunner { thread::park_timeout(park_timeout); } } - fn run_dynamic(&self, parker: &dyn Fn()) -> ! { + fn _dynamic_loop(&self, parker: &dyn Fn()) -> ! { loop { while let Ok(task) = POOL.receiver.try_recv() { trace!("dynamic thread: running task"); @@ -161,7 +209,7 @@ impl DynamicRunner for AsyncRunner { parker(); } } - fn run_standalone(&self) { + fn _standalone(&self) { while let Ok(task) = POOL.receiver.try_recv() { task.run(); } diff --git a/src/bastion-executor/src/run.rs b/src/bastion-executor/src/run.rs index 4a3d5757..9eb62f64 100644 --- a/src/bastion-executor/src/run.rs +++ b/src/bastion-executor/src/run.rs @@ -7,11 +7,11 @@ use crossbeam_utils::sync::Parker; use lightproc::proc_stack::ProcStack; use std::cell::{Cell, UnsafeCell}; use std::future::Future; +use std::mem; use std::mem::ManuallyDrop; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; -use std::{mem, panic}; /// /// This method blocks the current thread until passed future is resolved with an output (including the panic). diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index 36719493..d743540d 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -43,17 +43,17 @@ distributed = [ ] scaling = [] docs = ["distributed", "scaling", "default"] - +runtime-tokio = ["bastion-executor/runtime-tokio"] [package.metadata.docs.rs] features = ["docs"] rustdoc-args = ["--cfg", "feature=\"docs\""] [dependencies] -bastion-executor = "0.4.0" -lightproc = "0.3.5" -# bastion-executor = { version = "= 0.3.7-alpha.0", path = "../bastion-executor" } -# lightproc = { version = "= 0.3.6-alpha.0", path = "../lightproc" } +# bastion-executor = "0.4.0" +# lightproc = "0.3.5" +bastion-executor = { path = "../bastion-executor" } +lightproc = { path = "../lightproc" } lever = "0.1.1-alpha.11" futures = "0.3.5" @@ -75,6 +75,7 @@ tracing-subscriber = "0.2.6" tracing = "0.1.15" anyhow = "1.0.31" crossbeam-queue = "0.3.0" +log = "0.4.14" [target.'cfg(not(windows))'.dependencies] nuclei = "0.1.2-alpha.1" @@ -88,3 +89,6 @@ bastion-utils = { version = "0.3.2", path = "../bastion-utils" } rand = "0.7.3" rayon = "1.3.1" num_cpus = "1.13.0" +# hello_tokio example +tokio = { version="1.1", features = ["time"] } +bastion-executor = { path = "../bastion-executor", features = ["runtime-tokio"] } diff --git a/src/bastion/examples/hello_tokio.rs b/src/bastion/examples/hello_tokio.rs new file mode 100644 index 00000000..fae279d9 --- /dev/null +++ b/src/bastion/examples/hello_tokio.rs @@ -0,0 +1,83 @@ +use bastion::prelude::*; +#[cfg(feature = "runtime-tokio")] +use tokio; +use tracing::{error, info, warn, Level}; + +/// `cargo run --features=runtime-tokio --example hello_tokio` +/// +/// We are focusing on the contents of the msg! macro here. +/// If you would like to understand how the rest works, +/// Have a look at the `hello_world.rs` example instead :) +/// +/// Log output: +/// +/// Jan 31 11:54:14.372 ERROR hello_tokio: just received hello, world! +/// Jan 31 11:54:14.472 WARN hello_tokio: awaited 5 seconds +/// Jan 31 11:54:14.472 ERROR hello_tokio: waited for the blocking! to be complete! +/// Jan 31 11:54:14.473 ERROR hello_tokio: not waiting for spawn! to be complete, moving on! +/// Jan 31 11:54:24.473 WARN hello_tokio: the spawn! is complete +/// Jan 31 11:54:34.372 WARN hello_tokio: we're done, stopping the bastion! +#[cfg(feature = "runtime-tokio")] +fn main() { + // Initialize tracing logger + // so we get nice output on the console. + let subscriber = tracing_subscriber::fmt() + .with_max_level(Level::WARN) + .finish(); + tracing::subscriber::set_global_default(subscriber).unwrap(); + + Bastion::init(); + Bastion::start(); + let workers = Bastion::children(|children| { + children.with_exec(|ctx: BastionContext| { + async move { + msg! { + ctx.recv().await?, + msg: &'static str => { + // Printing the incoming msg + error!("just received {}", msg); + + // let's wait until a tokio powered future is complete + run!(blocking! { + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + warn!("awaited 5 seconds"); + }); + error!("waited for the blocking! to be complete!"); + + // let's spawn a tokio powered future and move on + spawn! { + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + warn!("the spawn! is complete"); + }; + error!("not waiting for spawn! to be complete, moving on!"); + }; + _: _ => (); + } + Ok(()) + } + }) + }) + .expect("Couldn't create the children group."); + + let asker = async { + workers.elems()[0] + .tell_anonymously("hello, world!") + .expect("Couldn't send the message."); + }; + run!(asker); + + // Let's wait until the blocking! and the spawn! are complete on the child side. + run!(blocking!({ + std::thread::sleep(std::time::Duration::from_secs(20)) + })); + + warn!("we're done, stopping the bastion!"); + + // We are done, stopping the bastion! + Bastion::stop(); +} + +#[cfg(not(feature = "runtime-tokio"))] +fn main() { + panic!("this example requires the runtime-tokio feature: `cargo run --features=runtime-tokio --example hello_tokio`") +} From affa0fe09b53da98d24c414dbcc92d963334dd5d Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 14:56:58 +0100 Subject: [PATCH 02/12] use tokio::main! --- src/bastion/Cargo.toml | 2 +- src/bastion/examples/hello_tokio.rs | 32 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index d743540d..26276671 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -90,5 +90,5 @@ rand = "0.7.3" rayon = "1.3.1" num_cpus = "1.13.0" # hello_tokio example -tokio = { version="1.1", features = ["time"] } +tokio = { version="1.1", features = ["time", "macros"] } bastion-executor = { path = "../bastion-executor", features = ["runtime-tokio"] } diff --git a/src/bastion/examples/hello_tokio.rs b/src/bastion/examples/hello_tokio.rs index fae279d9..1536c85e 100644 --- a/src/bastion/examples/hello_tokio.rs +++ b/src/bastion/examples/hello_tokio.rs @@ -1,3 +1,4 @@ +use anyhow::Result as AnyResult; use bastion::prelude::*; #[cfg(feature = "runtime-tokio")] use tokio; @@ -11,14 +12,21 @@ use tracing::{error, info, warn, Level}; /// /// Log output: /// -/// Jan 31 11:54:14.372 ERROR hello_tokio: just received hello, world! -/// Jan 31 11:54:14.472 WARN hello_tokio: awaited 5 seconds -/// Jan 31 11:54:14.472 ERROR hello_tokio: waited for the blocking! to be complete! -/// Jan 31 11:54:14.473 ERROR hello_tokio: not waiting for spawn! to be complete, moving on! -/// Jan 31 11:54:24.473 WARN hello_tokio: the spawn! is complete -/// Jan 31 11:54:34.372 WARN hello_tokio: we're done, stopping the bastion! +/// Jan 31 14:55:55.677 WARN hello_tokio: just spawned! +/// Jan 31 14:55:56.678 WARN hello_tokio: Ok let's handle a message now. +/// Jan 31 14:55:56.678 ERROR hello_tokio: just received hello, world! +/// Jan 31 14:55:56.678 WARN hello_tokio: sleeping for 2 seconds without using the bastion executor +/// Jan 31 14:55:58.680 WARN hello_tokio: and done! +/// Jan 31 14:55:58.681 WARN hello_tokio: let's sleep for 5 seconds within a blocking block +/// Jan 31 14:56:03.682 WARN hello_tokio: awaited 5 seconds +/// Jan 31 14:56:03.682 ERROR hello_tokio: waited for the blocking! to be complete! +/// Jan 31 14:56:03.682 ERROR hello_tokio: not waiting for spawn! to be complete, moving on! +/// Jan 31 14:56:03.683 WARN hello_tokio: let's sleep for 10 seconds within a spawn block +/// Jan 31 14:56:13.683 WARN hello_tokio: the spawn! is complete +/// Jan 31 14:56:15.679 WARN hello_tokio: we're done, stopping the bastion! #[cfg(feature = "runtime-tokio")] -fn main() { +#[tokio::main] +async fn main() -> AnyResult<()> { // Initialize tracing logger // so we get nice output on the console. let subscriber = tracing_subscriber::fmt() @@ -31,14 +39,22 @@ fn main() { let workers = Bastion::children(|children| { children.with_exec(|ctx: BastionContext| { async move { + warn!("just spawned!"); + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + warn!("Ok let's handle a message now."); msg! { ctx.recv().await?, msg: &'static str => { // Printing the incoming msg error!("just received {}", msg); + warn!("sleeping for 2 seconds without using the bastion executor"); + tokio::time::sleep(std::time::Duration::from_secs(2)).await; + warn!("and done!"); + // let's wait until a tokio powered future is complete run!(blocking! { + warn!("let's sleep for 5 seconds within a blocking block"); tokio::time::sleep(std::time::Duration::from_secs(5)).await; warn!("awaited 5 seconds"); }); @@ -46,6 +62,7 @@ fn main() { // let's spawn a tokio powered future and move on spawn! { + warn!("let's sleep for 10 seconds within a spawn block"); tokio::time::sleep(std::time::Duration::from_secs(10)).await; warn!("the spawn! is complete"); }; @@ -75,6 +92,7 @@ fn main() { // We are done, stopping the bastion! Bastion::stop(); + Ok(()) } #[cfg(not(feature = "runtime-tokio"))] From 1f56e3e5e6bb7b5f024a21f0ee26b240c85be182 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 17:29:56 +0100 Subject: [PATCH 03/12] runtime handles --- src/bastion-executor/src/blocking.rs | 87 ++++++++-------------- src/bastion-executor/src/pool.rs | 87 ++++++++-------------- src/bastion-executor/src/thread_manager.rs | 3 +- src/bastion/examples/hello_tokio.rs | 7 +- src/bastion/examples/tcp-servers.rs | 1 - src/bastion/src/context.rs | 2 +- src/bastion/tests/run_blocking.rs | 1 - 7 files changed, 71 insertions(+), 117 deletions(-) diff --git a/src/bastion-executor/src/blocking.rs b/src/bastion-executor/src/blocking.rs index 6a761885..4e3e171b 100644 --- a/src/bastion-executor/src/blocking.rs +++ b/src/bastion-executor/src/blocking.rs @@ -16,8 +16,6 @@ use std::iter::Iterator; use std::sync::Arc; use std::time::Duration; use std::{env, thread}; -#[cfg(feature = "runtime-tokio")] -use tokio::runtime; use tracing::trace; /// If low watermark isn't configured this is the default scaler value. @@ -39,70 +37,31 @@ where handle } -struct BlockingRunner {} +struct BlockingRunner { + // We keep a handle to the tokio runtime here to make sure + // it will never be dropped while the DynamicPoolManager is alive, + // In case we need to spin up some threads. + #[cfg(feature = "runtime-tokio")] + runtime_handle: tokio::runtime::Handle, +} impl DynamicRunner for BlockingRunner { fn run_static(&self, park_timeout: Duration) -> ! { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("static thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._static_loop(park_timeout) }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._static_loop(park_timeout) - } - } - fn run_dynamic(&self, parker: &dyn Fn()) -> ! { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("dynamic thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._dynamic_loop(parker) }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._dynamic_loop(parker) - } - } - fn run_standalone(&self) { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("standalone thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._standalone() }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._standalone() - } - } -} - -impl BlockingRunner { - fn _static_loop(&self, park_timeout: Duration) -> ! { loop { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { trace!("static thread: running task"); - task.run(); + self.run(task); } trace!("static: empty queue, parking with timeout"); thread::park_timeout(park_timeout); } } - fn _dynamic_loop(&self, parker: &dyn Fn()) -> ! { + fn run_dynamic(&self, parker: &dyn Fn()) -> ! { loop { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { trace!("dynamic thread: running task"); - task.run(); + self.run(task); } trace!( "dynamic thread: parking - {:?}", @@ -111,13 +70,27 @@ impl BlockingRunner { parker(); } } - fn _standalone(&self) { + fn run_standalone(&self) { while let Ok(task) = POOL.receiver.recv_timeout(THREAD_RECV_TIMEOUT) { - task.run(); + self.run(task); } trace!("standalone thread: quitting."); } } + +impl BlockingRunner { + fn run(&self, task: LightProc) { + #[cfg(feature = "runtime-tokio")] + { + self.runtime_handle.spawn_blocking(|| task.run()); + } + #[cfg(not(feature = "runtime-tokio"))] + { + task.run(); + } + } +} + /// Pool interface between the scheduler and thread pool struct Pool { sender: Sender, @@ -127,7 +100,13 @@ struct Pool { static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - let runner = Arc::new(BlockingRunner {}); + let runner = Arc::new(BlockingRunner { + // We use current() here instead of try_current() + // because we want bastion to crash as soon as possible + // if there is no available runtime. + #[cfg(feature = "runtime-tokio")] + runtime_handle: tokio::runtime::Handle::current(), + }); DYNAMIC_POOL_MANAGER .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) diff --git a/src/bastion-executor/src/pool.rs b/src/bastion-executor/src/pool.rs index 8b591d45..bc819e7c 100644 --- a/src/bastion-executor/src/pool.rs +++ b/src/bastion-executor/src/pool.rs @@ -17,8 +17,6 @@ use std::iter::Iterator; use std::sync::Arc; use std::time::Duration; use std::{env, thread}; -#[cfg(feature = "runtime-tokio")] -use tokio::runtime; use tracing::trace; /// @@ -136,71 +134,31 @@ pub struct Pool { receiver: Receiver, } -struct AsyncRunner {} +struct AsyncRunner { + // We keep a handle to the tokio runtime here to make sure + // it will never be dropped while the DynamicPoolManager is alive, + // In case we need to spin up some threads. + #[cfg(feature = "runtime-tokio")] + runtime_handle: tokio::runtime::Handle, +} impl DynamicRunner for AsyncRunner { fn run_static(&self, park_timeout: Duration) -> ! { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("static thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._static_loop(park_timeout) }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._static_loop(park_timeout) - } - } - fn run_dynamic(&self, parker: &dyn Fn()) -> ! { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("dynamic thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._dynamic_loop(parker) }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._dynamic_loop(parker) - } - } - fn run_standalone(&self) { - #[cfg(feature = "runtime-tokio")] - { - let thread_runtime = runtime::Builder::new_multi_thread() - .enable_all() - .build() - .expect("standalone thread: couldn't spawn tokio runtime"); - thread_runtime.block_on(async move { self._standalone() }) - } - #[cfg(not(feature = "runtime-tokio"))] - { - self._standalone() - } - self._standalone() - } -} - -impl AsyncRunner { - fn _static_loop(&self, park_timeout: Duration) -> ! { loop { for task in &POOL.receiver { trace!("static: running task"); - task.run(); + self.run(task); } trace!("static: empty queue, parking with timeout"); thread::park_timeout(park_timeout); } } - fn _dynamic_loop(&self, parker: &dyn Fn()) -> ! { + fn run_dynamic(&self, parker: &dyn Fn()) -> ! { loop { while let Ok(task) = POOL.receiver.try_recv() { trace!("dynamic thread: running task"); - task.run(); + self.run(task); } trace!( "dynamic thread: parking - {:?}", @@ -209,18 +167,37 @@ impl AsyncRunner { parker(); } } - fn _standalone(&self) { + fn run_standalone(&self) { while let Ok(task) = POOL.receiver.try_recv() { - task.run(); + self.run(task); } trace!("standalone thread: quitting."); } } +impl AsyncRunner { + fn run(&self, task: LightProc) { + #[cfg(feature = "runtime-tokio")] + { + self.runtime_handle.spawn_blocking(|| task.run()); + } + #[cfg(not(feature = "runtime-tokio"))] + { + task.run(); + } + } +} + static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - let runner = Arc::new(AsyncRunner {}); + let runner = Arc::new(AsyncRunner { + // We use current() here instead of try_current() + // because we want bastion to crash as soon as possible + // if there is no available runtime. + #[cfg(feature = "runtime-tokio")] + runtime_handle: tokio::runtime::Handle::current(), + }); DYNAMIC_POOL_MANAGER .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) diff --git a/src/bastion-executor/src/thread_manager.rs b/src/bastion-executor/src/thread_manager.rs index 2aa78b26..4f89dc08 100644 --- a/src/bastion-executor/src/thread_manager.rs +++ b/src/bastion-executor/src/thread_manager.rs @@ -216,8 +216,7 @@ impl DynamicPoolManager { .name("bastion-driver-dynamic".to_string()) .spawn(move || { Self::affinity_pinner(); - let parker = || self.park_thread(); - clone.run_dynamic(&parker); + clone.run_dynamic(&|| self.park_thread()); }) .expect("cannot start dynamic thread"); }); diff --git a/src/bastion/examples/hello_tokio.rs b/src/bastion/examples/hello_tokio.rs index 1536c85e..ea2039d2 100644 --- a/src/bastion/examples/hello_tokio.rs +++ b/src/bastion/examples/hello_tokio.rs @@ -2,7 +2,7 @@ use anyhow::Result as AnyResult; use bastion::prelude::*; #[cfg(feature = "runtime-tokio")] use tokio; -use tracing::{error, info, warn, Level}; +use tracing::{error, warn, Level}; /// `cargo run --features=runtime-tokio --example hello_tokio` /// @@ -88,10 +88,11 @@ async fn main() -> AnyResult<()> { std::thread::sleep(std::time::Duration::from_secs(20)) })); - warn!("we're done, stopping the bastion!"); - + warn!("we're done, asking bastion to stop!"); // We are done, stopping the bastion! + Bastion::kill(); Bastion::stop(); + warn!("bastion stopped!"); Ok(()) } diff --git a/src/bastion/examples/tcp-servers.rs b/src/bastion/examples/tcp-servers.rs index 41d4196a..a40d6734 100644 --- a/src/bastion/examples/tcp-servers.rs +++ b/src/bastion/examples/tcp-servers.rs @@ -21,7 +21,6 @@ async fn run(addr: impl ToSocketAddrs) -> io::Result<()> { // Spawn a task that echoes messages from the client back to it. spawn(echo(stream)); } - Ok(()) } #[cfg(target_os = "windows")] diff --git a/src/bastion/src/context.rs b/src/bastion/src/context.rs index 1a3bb22b..3228c8fe 100644 --- a/src/bastion/src/context.rs +++ b/src/bastion/src/context.rs @@ -426,7 +426,7 @@ impl BastionContext { message = self.recv().fuse() => { message.map_err(|_| ReceiveError::Other) }, - duration = Delay::new(timeout).fuse() => { + _ = Delay::new(timeout).fuse() => { Err(ReceiveError::Timeout(timeout)) } } diff --git a/src/bastion/tests/run_blocking.rs b/src/bastion/tests/run_blocking.rs index 101e4864..09c512b5 100644 --- a/src/bastion/tests/run_blocking.rs +++ b/src/bastion/tests/run_blocking.rs @@ -29,7 +29,6 @@ fn test_run_blocking() { _: _ => panic!(); } } - Ok(()) } }) }) From 5897bee81af00a3f433cfc93a96e5fcba94e0e6c Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 20:21:11 +0100 Subject: [PATCH 04/12] wip, adding tests and making them compatible with runtime-tokio --- src/bastion-executor/src/blocking.rs | 31 ++-- src/bastion-executor/src/pool.rs | 31 ++-- src/bastion/Cargo.toml | 3 +- src/bastion/examples/hello_tokio.rs | 1 - src/bastion/src/context.rs | 17 +- src/bastion/tests/message_signatures.rs | 27 +++- ...op_children_broadcast.proptest-regressions | 8 + src/bastion/tests/prop_children_broadcast.rs | 70 +++++--- ...prop_children_message.proptest-regressions | 7 + src/bastion/tests/prop_children_message.rs | 97 ++++++----- ...p_children_redundancy.proptest-regressions | 8 + src/bastion/tests/prop_children_redundancy.rs | 60 ++++--- src/bastion/tests/run_blocking.rs | 19 ++- src/bastion/tests/tokio_runtime.rs | 152 ++++++++++++++++++ 14 files changed, 416 insertions(+), 115 deletions(-) create mode 100644 src/bastion/tests/prop_children_broadcast.proptest-regressions create mode 100644 src/bastion/tests/prop_children_message.proptest-regressions create mode 100644 src/bastion/tests/prop_children_redundancy.proptest-regressions create mode 100644 src/bastion/tests/tokio_runtime.rs diff --git a/src/bastion-executor/src/blocking.rs b/src/bastion-executor/src/blocking.rs index 4e3e171b..d26dd377 100644 --- a/src/bastion-executor/src/blocking.rs +++ b/src/bastion-executor/src/blocking.rs @@ -100,17 +100,28 @@ struct Pool { static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - let runner = Arc::new(BlockingRunner { - // We use current() here instead of try_current() - // because we want bastion to crash as soon as possible - // if there is no available runtime. - #[cfg(feature = "runtime-tokio")] - runtime_handle: tokio::runtime::Handle::current(), - }); + #[cfg(feature = "runtime-tokio")] + { + let runner = Arc::new(BlockingRunner { + // We use current() here instead of try_current() + // because we want bastion to crash as soon as possible + // if there is no available runtime. + runtime_handle: tokio::runtime::Handle::current(), + }); + + DYNAMIC_POOL_MANAGER + .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) + .expect("couldn't create dynamic pool manager"); + } + #[cfg(not(feature = "runtime-tokio"))] + { + let runner = Arc::new(BlockingRunner {}); + + DYNAMIC_POOL_MANAGER + .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) + .expect("couldn't create dynamic pool manager"); + } - DYNAMIC_POOL_MANAGER - .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) - .expect("couldn't create dynamic pool manager"); DYNAMIC_POOL_MANAGER .get() .expect("couldn't get static pool manager") diff --git a/src/bastion-executor/src/pool.rs b/src/bastion-executor/src/pool.rs index bc819e7c..8327ca32 100644 --- a/src/bastion-executor/src/pool.rs +++ b/src/bastion-executor/src/pool.rs @@ -191,17 +191,28 @@ impl AsyncRunner { static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - let runner = Arc::new(AsyncRunner { - // We use current() here instead of try_current() - // because we want bastion to crash as soon as possible - // if there is no available runtime. - #[cfg(feature = "runtime-tokio")] - runtime_handle: tokio::runtime::Handle::current(), - }); + #[cfg(feature = "runtime-tokio")] + { + let runner = Arc::new(AsyncRunner { + // We use current() here instead of try_current() + // because we want bastion to crash as soon as possible + // if there is no available runtime. + runtime_handle: tokio::runtime::Handle::current(), + }); + + DYNAMIC_POOL_MANAGER + .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) + .expect("couldn't create dynamic pool manager"); + } + #[cfg(not(feature = "runtime-tokio"))] + { + let runner = Arc::new(AsyncRunner {}); + + DYNAMIC_POOL_MANAGER + .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) + .expect("couldn't create dynamic pool manager"); + } - DYNAMIC_POOL_MANAGER - .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) - .expect("couldn't create dynamic pool manager"); DYNAMIC_POOL_MANAGER .get() .expect("couldn't get static pool manager") diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index 26276671..a5d9fa2f 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -91,4 +91,5 @@ rayon = "1.3.1" num_cpus = "1.13.0" # hello_tokio example tokio = { version="1.1", features = ["time", "macros"] } -bastion-executor = { path = "../bastion-executor", features = ["runtime-tokio"] } +bastion-executor = { path = "../bastion-executor" } +once_cell = "1.5.2" \ No newline at end of file diff --git a/src/bastion/examples/hello_tokio.rs b/src/bastion/examples/hello_tokio.rs index ea2039d2..e11f906f 100644 --- a/src/bastion/examples/hello_tokio.rs +++ b/src/bastion/examples/hello_tokio.rs @@ -90,7 +90,6 @@ async fn main() -> AnyResult<()> { warn!("we're done, asking bastion to stop!"); // We are done, stopping the bastion! - Bastion::kill(); Bastion::stop(); warn!("bastion stopped!"); Ok(()) diff --git a/src/bastion/src/context.rs b/src/bastion/src/context.rs index 3228c8fe..f871415d 100644 --- a/src/bastion/src/context.rs +++ b/src/bastion/src/context.rs @@ -699,7 +699,22 @@ mod context_tests { use crate::Bastion; use std::panic; - #[test] + #[cfg(feature = "runtime-tokio")] + mod tokio_tests { + #[tokio::test] + async fn test_context() { + super::test_context() + } + } + + #[cfg(not(feature = "runtime-tokio"))] + mod no_tokio_tests { + #[test] + fn test_context() { + super::test_context() + } + } + fn test_context() { Bastion::init(); Bastion::start(); diff --git a/src/bastion/tests/message_signatures.rs b/src/bastion/tests/message_signatures.rs index d4131fe7..2ac404db 100644 --- a/src/bastion/tests/message_signatures.rs +++ b/src/bastion/tests/message_signatures.rs @@ -42,11 +42,28 @@ fn spawn_responders() -> ChildrenRef { .expect("Couldn't create the children group.") } -#[test] -fn answer_and_tell_signatures() { - setup(); - Bastion::spawn(run).unwrap(); - teardown(); +#[cfg(feature = "runtime-tokio")] +mod tokio_tests { + use super::*; + + #[tokio::test] + async fn answer_and_tell_signatures() { + setup(); + Bastion::spawn(run).unwrap(); + teardown(); + } +} + +#[cfg(not(feature = "runtime-tokio"))] +mod no_tokio_tests { + use super::*; + + #[test] + fn answer_and_tell_signatures() { + setup(); + Bastion::spawn(run).unwrap(); + teardown(); + } } async fn run(ctx: BastionContext) -> Result<(), ()> { diff --git a/src/bastion/tests/prop_children_broadcast.proptest-regressions b/src/bastion/tests/prop_children_broadcast.proptest-regressions new file mode 100644 index 00000000..0581f2f2 --- /dev/null +++ b/src/bastion/tests/prop_children_broadcast.proptest-regressions @@ -0,0 +1,8 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 70c25a250dab8458e4c6eced0bd8d0b0925a85cab0e33fe71a3c527b8b3780c2 # shrinks to message = "" +cc 0ce425dcb58b6d604391a2b073f13559ce8e882abe9aeaa760fe7c97b2f5d610 # shrinks to message = "\u{10a39}🢰ûѨ*� .﹪/3t\\ஞ0\"Ⱥ\'ቒ1" diff --git a/src/bastion/tests/prop_children_broadcast.rs b/src/bastion/tests/prop_children_broadcast.rs index 12216e3b..4d2b8e13 100644 --- a/src/bastion/tests/prop_children_broadcast.rs +++ b/src/bastion/tests/prop_children_broadcast.rs @@ -4,32 +4,54 @@ use std::sync::Once; static START: Once = Once::new(); -proptest! { - #![proptest_config(ProptestConfig::with_cases(1_000))] - #[test] - fn proptest_bcast_message(message in "\\PC*") { - START.call_once(|| { - Bastion::init(); - }); - Bastion::start(); +#[cfg(feature = "runtime-tokio")] +mod tokio_proptests { + use super::*; + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_bcast_message(message in "\\PC*") { + tokio::runtime::Runtime::new().unwrap().block_on(async { + super::test_with_message(message); - if let Ok(_chrn) = Bastion::children(|children: Children| { - children - .with_exec(move |ctx: BastionContext| { - async move { - msg! { ctx.recv().await?, - ref _msg: &'static str => {}; - // This won't happen because this example - // only "asks" a `&'static str`... - _: _ => {}; - } + }); + } + } +} +#[cfg(not(feature = "runtime-tokio"))] +mod not_tokio_proptests { + use super::*; - Ok(()) - } - }) - }){ - let message: &'static str = Box::leak(message.into_boxed_str()); - Bastion::broadcast(message).expect("broadcast failed"); + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_bcast_message(message in "\\PC*") { + super::test_with_message(message); } } } + +fn test_with_message(message: String) { + START.call_once(|| { + Bastion::init(); + }); + Bastion::start(); + + if let Ok(_chrn) = Bastion::children(|children: Children| { + children.with_exec(move |ctx: BastionContext| { + async move { + msg! { ctx.recv().await?, + ref _msg: &'static str => {}; + // This won't happen because this example + // only "asks" a `&'static str`... + _: _ => {}; + } + + Ok(()) + } + }) + }) { + let message: &'static str = Box::leak(message.into_boxed_str()); + Bastion::broadcast(message).expect("broadcast failed"); + } +} diff --git a/src/bastion/tests/prop_children_message.proptest-regressions b/src/bastion/tests/prop_children_message.proptest-regressions new file mode 100644 index 00000000..0b089acd --- /dev/null +++ b/src/bastion/tests/prop_children_message.proptest-regressions @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 8428d777018d9727329e319192aecdc1187db6917e2a518fd7fd2e285cae0d8d # shrinks to message = "" diff --git a/src/bastion/tests/prop_children_message.rs b/src/bastion/tests/prop_children_message.rs index ba2ea5f2..4eaa7d4f 100644 --- a/src/bastion/tests/prop_children_message.rs +++ b/src/bastion/tests/prop_children_message.rs @@ -5,42 +5,65 @@ use std::sync::Once; static START: Once = Once::new(); -proptest! { - #![proptest_config(ProptestConfig::with_cases(1_000))] - #[test] - fn proptest_intra_message(message in "\\PC*") { - START.call_once(|| { - Bastion::init(); - }); - Bastion::start(); - - let message = Arc::new(message); - - let _ = Bastion::children(|children| { - children - .with_exec(move |ctx: BastionContext| { - let message = (*message).clone(); - async move { - let message: &'static str = Box::leak(message.into_boxed_str()); - let answer = ctx - .ask(&ctx.current().addr(), message) - .expect("Couldn't send the message."); - - msg! { ctx.recv().await?, - msg: &'static str =!> { - let _ = answer!(ctx, msg); - }; - _: _ => (); - } - - msg! { answer.await?, - _msg: &'static str => {}; - _: _ => {}; - } - - Ok(()) - } - }) - }); +#[cfg(feature = "runtime-tokio")] +mod tokio_proptests { + use super::*; + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_intra_message(message in "\\PC*") { + tokio::runtime::Runtime::new().unwrap().block_on(async { + super::test_with_message(message); + + }); + } + } +} + +#[cfg(not(feature = "runtime-tokio"))] +mod not_tokio_proptests { + use super::*; + + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_intra_message(message in "\\PC*") { + super::test_with_message(message); + } } } + +fn test_with_message(message: String) { + START.call_once(|| { + Bastion::init(); + }); + Bastion::start(); + + let message = Arc::new(message); + + let _ = Bastion::children(|children| { + children.with_exec(move |ctx: BastionContext| { + let message = (*message).clone(); + async move { + let message: &'static str = Box::leak(message.into_boxed_str()); + let answer = ctx + .ask(&ctx.current().addr(), message) + .expect("Couldn't send the message."); + + msg! { ctx.recv().await?, + msg: &'static str =!> { + let _ = answer!(ctx, msg); + }; + _: _ => (); + } + + msg! { answer.await?, + _msg: &'static str => {}; + _: _ => {}; + } + + Ok(()) + } + }) + }); +} diff --git a/src/bastion/tests/prop_children_redundancy.proptest-regressions b/src/bastion/tests/prop_children_redundancy.proptest-regressions new file mode 100644 index 00000000..3ed3661e --- /dev/null +++ b/src/bastion/tests/prop_children_redundancy.proptest-regressions @@ -0,0 +1,8 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 3133d59d522ffc52f22b079bc8288d5886ff9879d77ab2963132823345052892 # shrinks to r = 0 +cc 886d80a24e6a7e9241ad63841ded2f66f85d477041f292c5029542de1b38e40e # shrinks to r = 0 diff --git a/src/bastion/tests/prop_children_redundancy.rs b/src/bastion/tests/prop_children_redundancy.rs index a5a03eb4..59882654 100644 --- a/src/bastion/tests/prop_children_redundancy.rs +++ b/src/bastion/tests/prop_children_redundancy.rs @@ -1,33 +1,45 @@ use bastion::prelude::*; use proptest::prelude::*; +use std::sync::Arc; use std::sync::Once; static START: Once = Once::new(); -proptest! { - #![proptest_config(ProptestConfig::with_cases(1_000))] - #[test] - fn proptest_redundancy(r in std::usize::MIN..32) { - START.call_once(|| { - Bastion::init(); - }); - Bastion::start(); +// TODO [igni]: Figure out how to make it work with feature = "runtime-tokio" +#[cfg(not(feature = "runtime-tokio"))] +mod not_tokio_proptests { + use super::*; - Bastion::children(|children| { - children - // shrink over the redundancy - .with_redundancy(r) - .with_exec(|_ctx: BastionContext| { - async move { - // It's a proptest, - // we just don't want the loop - // to be optimized away - #[allow(clippy::drop_copy)] - loop { - std::mem::drop(()); - } - } - }) - }).expect("Coudn't spawn children."); + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_redundancy(r in std::usize::MIN..32) { + super::test_with_usize(r); + } } } + +fn test_with_usize(r: usize) { + START.call_once(|| { + Bastion::init(); + }); + Bastion::start(); + + Bastion::children(|children| { + children + // shrink over the redundancy + .with_redundancy(r) + .with_exec(|_ctx: BastionContext| { + async move { + // It's a proptest, + // we just don't want the loop + // to be optimized away + #[allow(clippy::drop_copy)] + loop { + std::mem::drop(()); + } + } + }) + }) + .expect("Coudn't spawn children."); +} diff --git a/src/bastion/tests/run_blocking.rs b/src/bastion/tests/run_blocking.rs index 09c512b5..1ebbd596 100644 --- a/src/bastion/tests/run_blocking.rs +++ b/src/bastion/tests/run_blocking.rs @@ -6,8 +6,23 @@ use std::sync::{ use std::thread; use std::time::Duration; -#[test] -fn test_run_blocking() { +#[cfg(feature = "runtime-tokio")] +mod tokio_tests { + #[tokio::test] + async fn test_run_blocking() { + super::run() + } +} + +#[cfg(not(feature = "runtime-tokio"))] +mod not_tokio_tests { + #[test] + fn test_run_blocking() { + super::run() + } +} + +fn run() { Bastion::init(); Bastion::start(); diff --git a/src/bastion/tests/tokio_runtime.rs b/src/bastion/tests/tokio_runtime.rs new file mode 100644 index 00000000..f355db00 --- /dev/null +++ b/src/bastion/tests/tokio_runtime.rs @@ -0,0 +1,152 @@ +#[cfg(feature = "runtime-tokio")] +mod tokio_tests { + + use bastion::prelude::*; + + #[tokio::test] + async fn test_simple_await() { + tokio::time::sleep(std::time::Duration::from_nanos(1)).await; + } + + #[tokio::test] + async fn test_within_children() { + Bastion::init(); + Bastion::start(); + + Bastion::children(|children| { + children.with_exec(|_| async move { + tokio::time::sleep(std::time::Duration::from_nanos(1)).await; + Ok(()) + }) + }) + .expect("Couldn't create the children group."); + + Bastion::stop(); + } + + #[tokio::test] + async fn test_within_message_receive() { + Bastion::init(); + Bastion::start(); + + let workers = Bastion::children(|children| { + children.with_exec(|ctx| async move { + msg! { + ctx.recv().await?, + question: &'static str =!> { + if question != "marco" { + panic!("didn't receive expected message"); + } + tokio::time::sleep(std::time::Duration::from_nanos(1)).await; + answer!(ctx, "polo").expect("couldn't send answer"); + }; + _: _ => { + panic!("didn't receive &str"); + }; + } + Ok(()) + }) + }) + .expect("Couldn't create the children group."); + + let answer = workers.elems()[0] + .ask_anonymously("marco") + .expect("Couldn't send the message."); + + msg! { answer.await.expect("couldn't receive answer"), + reply: &'static str => { + if reply != "polo" { + panic!("didn't receive expected message"); + } + }; + _: _ => { panic!("didn't receive &str"); }; + } + Bastion::stop(); + } + + #[tokio::test] + async fn test_within_message_receive_blocking() { + Bastion::init(); + Bastion::start(); + + let workers = Bastion::children(|children| { + children.with_exec(|ctx| async move { + msg! { + ctx.recv().await?, + question: &'static str =!> { + if question != "marco" { + panic!("didn't receive expected message"); + } + run!(blocking! { + let _ = tokio::time::sleep(std::time::Duration::from_nanos(1)).await; + println!("done"); + }); + answer!(ctx, "polo").expect("couldn't send answer"); + }; + _: _ => { + panic!("didn't receive &str"); + }; + } + Ok(()) + }) + }) + .expect("Couldn't create the children group."); + + let answer = workers.elems()[0] + .ask_anonymously("marco") + .expect("Couldn't send the message."); + + msg! { answer.await.expect("couldn't receive answer"), + reply: &'static str => { + if reply != "polo" { + panic!("didn't receive expected message"); + } + }; + _: _ => { panic!("didn't receive &str"); }; + } + Bastion::stop(); + } + + #[tokio::test] + async fn test_within_message_receive_spawn() { + Bastion::init(); + Bastion::start(); + + let workers = Bastion::children(|children| { + children.with_exec(|ctx| async move { + msg! { + ctx.recv().await?, + question: &'static str =!> { + if question != "marco" { + panic!("didn't receive expected message"); + } + run!(blocking! { + let _ = tokio::time::sleep(std::time::Duration::from_nanos(1)).await; + println!("done"); + }); + answer!(ctx, "polo").expect("couldn't send answer"); + }; + _: _ => { + panic!("didn't receive &str"); + }; + } + Ok(()) + }) + }) + .expect("Couldn't create the children group."); + + let answer = workers.elems()[0] + .ask_anonymously("marco") + .expect("Couldn't send the message."); + + msg! { answer.await.expect("couldn't receive answer"), + reply: &'static str => { + if reply != "polo" { + panic!("didn't receive expected message"); + } + }; + _: _ => { panic!("didn't receive &str"); }; + } + Bastion::stop(); + } +} From c5b92f1b13ff2a5bf3a50f427f43d0f0d89748ea Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 20:43:58 +0100 Subject: [PATCH 05/12] ok docs remaining, no clue how to handle it --- src/bastion-executor/tests/lib.rs | 17 ++++++++++--- src/bastion-executor/tests/run_blocking.rs | 19 +++++++++++++-- src/bastion/tests/tokio_runtime.rs | 28 ++++++++-------------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/bastion-executor/tests/lib.rs b/src/bastion-executor/tests/lib.rs index 2a3c9f8b..8d87ca9c 100644 --- a/src/bastion-executor/tests/lib.rs +++ b/src/bastion-executor/tests/lib.rs @@ -8,8 +8,19 @@ mod tests { dbg!(core_ids); } - #[test] - fn pool_check() { - pool::get(); + #[cfg(feature = "runtime-tokio")] + mod tokio_tests { + #[tokio::test] + async fn pool_check() { + super::pool::get(); + } + } + + #[cfg(not(feature = "runtime-tokio"))] + mod no_tokio_tests { + #[test] + fn pool_check() { + super::pool::get(); + } } } diff --git a/src/bastion-executor/tests/run_blocking.rs b/src/bastion-executor/tests/run_blocking.rs index 30f083d9..a454b906 100644 --- a/src/bastion-executor/tests/run_blocking.rs +++ b/src/bastion-executor/tests/run_blocking.rs @@ -4,8 +4,23 @@ use lightproc::proc_stack::ProcStack; use std::thread; use std::time::Duration; -#[test] -fn test_run_blocking() { +#[cfg(feature = "runtime-tokio")] +mod tokio_tests { + #[tokio::test] + async fn test_run_blocking() { + super::run_test() + } +} + +#[cfg(not(feature = "runtime-tokio"))] +mod no_tokio_tests { + #[test] + fn test_run_blocking() { + super::run_test() + } +} + +fn run_test() { let output = run( blocking::spawn_blocking( async { diff --git a/src/bastion/tests/tokio_runtime.rs b/src/bastion/tests/tokio_runtime.rs index f355db00..64784da3 100644 --- a/src/bastion/tests/tokio_runtime.rs +++ b/src/bastion/tests/tokio_runtime.rs @@ -9,10 +9,19 @@ mod tokio_tests { } #[tokio::test] - async fn test_within_children() { + async fn test_within_bastion() { Bastion::init(); Bastion::start(); + test_within_children().await; + test_within_message_receive().await; + test_within_message_receive_blocking().await; + test_within_message_receive_spawn().await; + + Bastion::stop(); + } + + async fn test_within_children() { Bastion::children(|children| { children.with_exec(|_| async move { tokio::time::sleep(std::time::Duration::from_nanos(1)).await; @@ -20,15 +29,9 @@ mod tokio_tests { }) }) .expect("Couldn't create the children group."); - - Bastion::stop(); } - #[tokio::test] async fn test_within_message_receive() { - Bastion::init(); - Bastion::start(); - let workers = Bastion::children(|children| { children.with_exec(|ctx| async move { msg! { @@ -61,14 +64,9 @@ mod tokio_tests { }; _: _ => { panic!("didn't receive &str"); }; } - Bastion::stop(); } - #[tokio::test] async fn test_within_message_receive_blocking() { - Bastion::init(); - Bastion::start(); - let workers = Bastion::children(|children| { children.with_exec(|ctx| async move { msg! { @@ -104,14 +102,9 @@ mod tokio_tests { }; _: _ => { panic!("didn't receive &str"); }; } - Bastion::stop(); } - #[tokio::test] async fn test_within_message_receive_spawn() { - Bastion::init(); - Bastion::start(); - let workers = Bastion::children(|children| { children.with_exec(|ctx| async move { msg! { @@ -147,6 +140,5 @@ mod tokio_tests { }; _: _ => { panic!("didn't receive &str"); }; } - Bastion::stop(); } } From 32f2a366ce7ac2b258e8a130b35dfd0d565ecfec Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 21:03:49 +0100 Subject: [PATCH 06/12] wip, doctests --- src/bastion/src/bastion.rs | 144 ++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/src/bastion/src/bastion.rs b/src/bastion/src/bastion.rs index af6f231b..b57d9b24 100644 --- a/src/bastion/src/bastion.rs +++ b/src/bastion/src/bastion.rs @@ -29,7 +29,18 @@ distributed_api! { /// ```rust /// use bastion::prelude::*; /// -/// fn main() { +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// fn run() { /// /// Creating the system's configuration... /// let config = Config::new().hide_backtraces(); /// // ...and initializing the system with it (this is required)... @@ -172,6 +183,18 @@ impl Bastion { /// # Example /// /// ```rust + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// use bastion::prelude::*; /// /// Bastion::init(); @@ -181,6 +204,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Config`]: struct.Config.html @@ -206,6 +230,18 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// let config = Config::new() /// .show_backtraces(); /// @@ -216,6 +252,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Config`]: struct.Config.html @@ -248,6 +285,18 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let sp_ref: SupervisorRef = Bastion::supervisor(|sp| { @@ -259,6 +308,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -307,6 +357,18 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let children_ref: ChildrenRef = Bastion::children(|children| { @@ -328,6 +390,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Children`]: children/struct.Children.html @@ -357,6 +420,18 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let children_ref: ChildrenRef = Bastion::spawn(|ctx: BastionContext| { @@ -369,6 +444,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Children::with_exec`]: children/struct.Children.html#method.with_exec @@ -410,7 +486,18 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let msg = "A message containing data."; @@ -437,7 +524,7 @@ impl Bastion { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); - /// # } + /// # } /// ``` pub fn broadcast(msg: M) -> Result<(), M> { debug!("Bastion: Broadcasting message: {:?}", msg); @@ -459,6 +546,18 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// Bastion::init(); /// /// // Use bastion, spawn children and supervisors... @@ -470,6 +569,7 @@ impl Bastion { /// # /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn start() { debug!("Bastion: Starting."); @@ -488,6 +588,19 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { + /// /// Bastion::init(); /// /// // Use bastion, spawn children and supervisors... @@ -499,6 +612,7 @@ impl Bastion { /// /// Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn stop() { debug!("Bastion: Stopping."); @@ -517,6 +631,18 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// Bastion::init(); /// /// // Use bastion, spawn children and supervisors... @@ -527,6 +653,7 @@ impl Bastion { /// /// Bastion::kill(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn kill() { debug!("Bastion: Killing."); @@ -553,6 +680,18 @@ impl Bastion { /// # Example /// /// ```rust + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// use bastion::prelude::*; /// /// Bastion::init(); @@ -567,6 +706,7 @@ impl Bastion { /// Bastion::block_until_stopped(); /// // The system is now stopped. A child might have /// // stopped or killed it... + /// # } /// ``` /// /// [`Bastion::stop()`]: #method.stop From c154af64c1a0745ed0d58300b8d034f26ccf6202 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 21:20:31 +0100 Subject: [PATCH 07/12] wip: getting there... --- src/bastion/src/callbacks.rs | 78 ++++++++++++++++++ src/bastion/src/child_ref.rs | 74 +++++++++++++++++ src/bastion/src/children.rs | 102 +++++++++++++++++++++++ src/bastion/src/children_ref.rs | 76 +++++++++++++++++ src/bastion/src/config.rs | 39 +++++++++ src/bastion/src/context.rs | 141 ++++++++++++++++++++++++++++++++ 6 files changed, 510 insertions(+) diff --git a/src/bastion/src/callbacks.rs b/src/bastion/src/callbacks.rs index 0c271b96..18cef852 100644 --- a/src/bastion/src/callbacks.rs +++ b/src/bastion/src/callbacks.rs @@ -19,6 +19,18 @@ pub(crate) enum CallbackType { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -41,6 +53,7 @@ pub(crate) enum CallbackType { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -61,6 +74,18 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -83,6 +108,7 @@ impl Callbacks { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor::with_callbacks`]: supervisor/struct.Supervisor.html#method.with_callbacks @@ -107,6 +133,18 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|supervisor| { @@ -138,6 +176,7 @@ impl Callbacks { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -166,6 +205,18 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|supervisor| { @@ -199,6 +250,7 @@ impl Callbacks { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -227,6 +279,18 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|supervisor| { @@ -260,6 +324,7 @@ impl Callbacks { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -292,6 +357,18 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|supervisor| { @@ -323,6 +400,7 @@ impl Callbacks { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html diff --git a/src/bastion/src/child_ref.rs b/src/bastion/src/child_ref.rs index 139c830c..51520c3c 100644 --- a/src/bastion/src/child_ref.rs +++ b/src/bastion/src/child_ref.rs @@ -67,6 +67,18 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -82,6 +94,7 @@ impl ChildRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn id(&self) -> &BastionId { &self.id @@ -98,6 +111,18 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -114,6 +139,7 @@ impl ChildRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn is_public(&self) -> bool { self.is_public @@ -135,7 +161,18 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// // The message that will be "told"... /// const TELL_MSG: &'static str = "A message containing data (tell)."; @@ -195,7 +232,18 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// // The message that will be "asked"... /// const ASK_MSG: &'static str = "A message containing data (ask)."; @@ -277,6 +325,18 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # let children_ref = /// # Bastion::children(|children| { @@ -304,6 +364,7 @@ impl ChildRef { /// # /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn stop(&self) -> Result<(), ()> { debug!("ChildRef({}): Stopping.", self.id); @@ -323,6 +384,18 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -332,6 +405,7 @@ impl ChildRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn kill(&self) -> Result<(), ()> { debug!("ChildRef({}): Killing.", self.id()); diff --git a/src/bastion/src/children.rs b/src/bastion/src/children.rs index 174ccf82..e0474e4a 100644 --- a/src/bastion/src/children.rs +++ b/src/bastion/src/children.rs @@ -49,6 +49,18 @@ use tracing::{debug, trace, warn}; /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// let children_ref: ChildrenRef = Bastion::children(|children| { @@ -70,6 +82,7 @@ use tracing::{debug, trace, warn}; /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` /// /// [`with_redundancy`]: #method.with_redundancy @@ -157,6 +170,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -168,6 +193,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn id(&self) -> &BastionId { self.bcast.id() @@ -244,6 +270,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -263,6 +301,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn with_exec(mut self, init: I) -> Self where @@ -290,6 +329,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -300,6 +351,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`with_exec`]: #method.with_exec @@ -336,6 +388,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -348,6 +412,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// [`DispatcherHandler`]: ../dispatcher/trait.DispatcherHandler.html pub fn with_dispatcher(mut self, dispatcher: Dispatcher) -> Self { @@ -369,7 +434,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -409,6 +485,18 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -431,6 +519,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Callbacks`]: struct.Callbacks.html @@ -458,6 +547,18 @@ impl Children { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -476,6 +577,7 @@ impl Children { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// [`std::time::Duration`]: https://doc.rust-lang.org/nightly/core/time/struct.Duration.html pub fn with_heartbeat_tick(mut self, interval: Duration) -> Self { diff --git a/src/bastion/src/children_ref.rs b/src/bastion/src/children_ref.rs index 44313d61..af7a8c6e 100644 --- a/src/bastion/src/children_ref.rs +++ b/src/bastion/src/children_ref.rs @@ -52,6 +52,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let children_ref = Bastion::children(|children| { @@ -64,6 +76,7 @@ impl ChildrenRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn id(&self) -> &BastionId { &self.id @@ -77,6 +90,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -85,6 +110,7 @@ impl ChildrenRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`ChildRef`]: children/struct.ChildRef.html @@ -100,6 +126,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -108,6 +146,7 @@ impl ChildrenRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`ChildRef`]: children/struct.ChildRef.html @@ -135,7 +174,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -191,6 +241,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -199,6 +261,7 @@ impl ChildrenRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn stop(&self) -> Result<(), ()> { debug!("ChildrenRef({}): Stopping.", self.id()); @@ -219,6 +282,18 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -227,6 +302,7 @@ impl ChildrenRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn kill(&self) -> Result<(), ()> { debug!("ChildrenRef({}): Killing.", self.id()); diff --git a/src/bastion/src/config.rs b/src/bastion/src/config.rs index ceecf258..fe6c4f2e 100644 --- a/src/bastion/src/config.rs +++ b/src/bastion/src/config.rs @@ -10,6 +10,18 @@ /// ```rust /// use bastion::prelude::*; /// +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let config = Config::new().show_backtraces(); /// /// Bastion::init_with(config); @@ -19,6 +31,7 @@ /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` /// /// [`Bastion::init_with`]: struct.Bastion.html#method.init_with @@ -57,6 +70,18 @@ impl Config { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// let config = Config::new().show_backtraces(); /// /// Bastion::init_with(config); @@ -67,6 +92,7 @@ impl Config { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn show_backtraces(mut self) -> Self { self.backtraces = Backtraces::show(); @@ -83,6 +109,18 @@ impl Config { /// ```rust /// use bastion::prelude::*; /// + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// let config = Config::new().hide_backtraces(); /// /// Bastion::init_with(config); @@ -93,6 +131,7 @@ impl Config { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Config::show_backtraces`]: #method.show_backtraces diff --git a/src/bastion/src/context.rs b/src/bastion/src/context.rs index f871415d..b5713622 100644 --- a/src/bastion/src/context.rs +++ b/src/bastion/src/context.rs @@ -42,6 +42,18 @@ pub const NIL_ID: BastionId = BastionId(Uuid::nil()); /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -57,6 +69,7 @@ pub const NIL_ID: BastionId = BastionId(Uuid::nil()); /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` pub struct BastionId(pub(crate) Uuid); @@ -71,6 +84,18 @@ pub struct BastionId(pub(crate) Uuid); /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -103,6 +128,7 @@ pub struct BastionId(pub(crate) Uuid); /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` pub struct BastionContext { id: BastionId, @@ -155,6 +181,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -172,6 +210,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`ChildRef`]: children/struct.ChildRef.html @@ -187,6 +226,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -204,6 +255,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`ChildrenRef`]: children/struct.ChildrenRef.html @@ -222,6 +274,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// // When calling the method from a children group supervised @@ -258,6 +322,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`SupervisorRef`]: supervisor/struct.SupervisorRef.html @@ -283,6 +348,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -300,6 +377,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`recv`]: #method.recv @@ -339,6 +417,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -355,6 +445,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`try_recv`]: #method.try_recv @@ -390,6 +481,18 @@ impl BastionContext { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -411,6 +514,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`recv`]: #method.recv @@ -439,6 +543,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// @@ -455,6 +571,7 @@ impl BastionContext { /// # /// # Bastion::start(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`RefAddr`]: /prelude/struct.Answer.html @@ -477,6 +594,18 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -496,6 +625,7 @@ impl BastionContext { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`RefAddr`]: ../prelude/struct.RefAddr.html @@ -529,7 +659,18 @@ impl BastionContext { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// // The message that will be "asked"... /// const ASK_MSG: &'static str = "A message containing data (ask)."; From 007ea8c78e59a302044f291f245f33b8a1599e26 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 21:32:15 +0100 Subject: [PATCH 08/12] tests are finally passing! --- src/bastion-executor/src/pool.rs | 13 ++ src/bastion/src/envelope.rs | 61 +++++++++ src/bastion/src/executor.rs | 39 ++++++ src/bastion/src/macros.rs | 55 +++++++++ src/bastion/src/message.rs | 44 +++++++ src/bastion/src/path.rs | 70 +++++++++++ src/bastion/src/supervisor.rs | 206 +++++++++++++++++++++++++++++++ 7 files changed, 488 insertions(+) diff --git a/src/bastion-executor/src/pool.rs b/src/bastion-executor/src/pool.rs index 8327ca32..bc84bb3f 100644 --- a/src/bastion-executor/src/pool.rs +++ b/src/bastion-executor/src/pool.rs @@ -27,6 +27,18 @@ use tracing::trace; /// use bastion_executor::prelude::*; /// use lightproc::prelude::*; /// +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # start(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # start(); +/// # } +/// # +/// # fn start() { /// let pid = 1; /// let stack = ProcStack::default().with_pid(pid); /// @@ -43,6 +55,7 @@ use tracing::trace; /// }, /// stack.clone(), /// ); +/// # } /// ``` pub fn spawn(future: F, stack: ProcStack) -> RecoverableHandle where diff --git a/src/bastion/src/envelope.rs b/src/bastion/src/envelope.rs index a476ed69..6060c516 100644 --- a/src/bastion/src/envelope.rs +++ b/src/bastion/src/envelope.rs @@ -22,6 +22,18 @@ pub(crate) struct Envelope { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -37,6 +49,7 @@ pub(crate) struct Envelope { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` pub struct SignedMessage { pub(crate) msg: Msg, @@ -60,6 +73,18 @@ impl SignedMessage { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -75,6 +100,7 @@ impl SignedMessage { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn signature(&self) -> &RefAddr { &self.sign @@ -89,6 +115,18 @@ impl SignedMessage { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// Bastion::children(|children| { @@ -106,6 +144,7 @@ impl SignedMessage { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` pub struct RefAddr { path: Arc, @@ -134,7 +173,18 @@ impl RefAddr { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -174,7 +224,18 @@ impl RefAddr { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); diff --git a/src/bastion/src/executor.rs b/src/bastion/src/executor.rs index 7e6d0c1e..2c052a71 100644 --- a/src/bastion/src/executor.rs +++ b/src/bastion/src/executor.rs @@ -10,10 +10,23 @@ use std::future::Future; /// # Example /// ``` /// # use std::{thread, time}; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// use bastion::executor::blocking; /// let task = blocking(async move { /// thread::sleep(time::Duration::from_millis(3000)); /// }); +/// # } /// ``` pub fn blocking(future: F) -> RecoverableHandle where @@ -29,6 +42,18 @@ where /// # Example /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// use bastion::executor::run; /// let future1 = async move { /// 123 @@ -45,6 +70,7 @@ where /// /// let result = run(future2); /// assert_eq!(result, 5); +/// # } /// ``` pub fn run(future: F) -> T where @@ -58,11 +84,24 @@ where /// # Example /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// use bastion::executor::{spawn, run}; /// let handle = spawn(async { /// panic!("test"); /// }); /// run(handle); +/// # } /// ``` pub fn spawn(future: F) -> RecoverableHandle where diff --git a/src/bastion/src/macros.rs b/src/bastion/src/macros.rs index 68d068e9..9bb64b7c 100644 --- a/src/bastion/src/macros.rs +++ b/src/bastion/src/macros.rs @@ -8,7 +8,18 @@ /// /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let children = children! { /// // the default redundancy is 1 /// redundancy: 100, @@ -133,7 +144,18 @@ macro_rules! children { /// # Example /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let sp = supervisor! { /// callbacks: Callbacks::default(), /// strategy: SupervisionStrategy::OneForAll, @@ -189,7 +211,18 @@ macro_rules! supervisor { /// # use std::{thread, time}; /// # use lightproc::proc_stack::ProcStack; /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let task = blocking! { /// thread::sleep(time::Duration::from_millis(3000)); /// }; @@ -211,7 +244,18 @@ macro_rules! blocking { /// # Example /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let future1 = async move { /// 123 /// }; @@ -245,7 +289,18 @@ macro_rules! run { /// # Example /// ``` /// # use bastion::prelude::*; +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// let handle = spawn! { /// panic!("test"); /// }; diff --git a/src/bastion/src/message.rs b/src/bastion/src/message.rs index 47b1d21d..b50fcdaf 100644 --- a/src/bastion/src/message.rs +++ b/src/bastion/src/message.rs @@ -49,7 +49,18 @@ pub struct AnswerSender(oneshot::Sender); /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// // The message that will be "asked"... /// const ASK_MSG: &'static str = "A message containing data (ask)."; @@ -125,7 +136,18 @@ pub struct Answer(Receiver); /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// Bastion::children(|children| { /// children.with_exec(|ctx: BastionContext| { @@ -572,7 +594,18 @@ impl Future for Answer { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// // The message that will be broadcasted... /// const BCAST_MSG: &'static str = "A message containing data (broadcast)."; @@ -776,7 +809,18 @@ macro_rules! msg { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # let children_ref = /// // Create a new child... diff --git a/src/bastion/src/path.rs b/src/bastion/src/path.rs index ab4fec16..82492bad 100644 --- a/src/bastion/src/path.rs +++ b/src/bastion/src/path.rs @@ -17,7 +17,18 @@ use std::result::Result; /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// /// # Bastion::children(|children| { @@ -72,7 +83,18 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -113,7 +135,18 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -154,7 +187,18 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let children_ref = Bastion::children(|children| children).unwrap(); @@ -263,6 +307,18 @@ impl fmt::Debug for BastionPath { /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// @@ -284,6 +340,7 @@ impl fmt::Debug for BastionPath { /// # /// # Bastion::start(); /// # Bastion::block_until_stopped(); +/// # } /// ``` pub enum BastionPathElement { #[doc(hidden)] @@ -333,6 +390,18 @@ impl BastionPathElement { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// /// Bastion::children(|children| { @@ -353,6 +422,7 @@ impl BastionPathElement { /// # /// # Bastion::start(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn is_child(&self) -> bool { matches!(self, BastionPathElement::Child(_)) diff --git a/src/bastion/src/supervisor.rs b/src/bastion/src/supervisor.rs index 17477c22..39d16c9d 100644 --- a/src/bastion/src/supervisor.rs +++ b/src/bastion/src/supervisor.rs @@ -44,6 +44,18 @@ use tracing::{debug, trace, warn}; /// ```rust /// # use bastion::prelude::*; /// # +/// # #[cfg(feature = "runtime-tokio")] +/// # #[tokio::main] +/// # async fn main() { +/// # run(); +/// # } +/// # +/// # #[cfg(not(feature = "runtime-tokio"))] +/// # fn main() { +/// # run(); +/// # } +/// # +/// # fn run() { /// # Bastion::init(); /// # /// let sp_ref: SupervisorRef = Bastion::supervisor(|sp| { @@ -55,6 +67,7 @@ use tracing::{debug, trace, warn}; /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); +/// # } /// ``` /// /// [`Children`]: children/struct.Children.html @@ -358,6 +371,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::supervisor(|sp| { @@ -370,6 +395,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn id(&self) -> &BastionId { &self.bcast.id() @@ -414,6 +440,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|parent| { @@ -427,6 +465,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`SupervisorRef`]: ../struct.SupervisorRef.html @@ -477,6 +516,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|mut parent| { @@ -491,6 +542,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`SupervisorRef`]: ../struct.SupervisorRef.html @@ -542,6 +594,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|sp| { @@ -563,6 +627,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Children`]: children/struct.Children.html @@ -619,6 +684,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # Bastion::supervisor(|mut sp| { @@ -641,6 +718,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Children`]: children/struct.Children.html @@ -708,6 +786,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::supervisor(|sp| { @@ -718,6 +808,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`SupervisionStrategy::OneForOne`]: supervisor/enum.SupervisionStrategy.html#variant.OneForOne @@ -746,6 +837,18 @@ impl Supervisor { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # Bastion::supervisor(|sp| { /// sp.with_restart_strategy( @@ -763,6 +866,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn with_restart_strategy(mut self, restart_strategy: RestartStrategy) -> Self { trace!( @@ -790,6 +894,18 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// Bastion::supervisor(|sp| { @@ -803,6 +919,7 @@ impl Supervisor { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Callbacks`]: struct.Callbacks.html @@ -1400,6 +1517,18 @@ impl SupervisorRef { /// ```rust /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// let supervisor_ref = Bastion::supervisor(|sp| { @@ -1412,6 +1541,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn id(&self) -> &BastionId { &self.id @@ -1435,6 +1565,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let mut parent_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1447,6 +1589,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Supervisor`]: supervisor/struct.Supervisor.html @@ -1498,6 +1641,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let sp_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1518,6 +1673,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`Children`]: children/struct.Children.html @@ -1596,6 +1752,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let sp_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1605,6 +1773,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` /// /// [`SupervisionStrategy::OneForOne`]: supervisor/enum.SupervisionStrategy.html#variant.OneForOne @@ -1637,7 +1806,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let sp_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1693,6 +1873,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let sp_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1701,6 +1893,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn stop(&self) -> Result<(), ()> { debug!("SupervisorRef({}): Stopping.", self.id()); @@ -1721,6 +1914,18 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # + /// # #[cfg(feature = "runtime-tokio")] + /// # #[tokio::main] + /// # async fn main() { + /// # run(); + /// # } + /// # + /// # #[cfg(not(feature = "runtime-tokio"))] + /// # fn main() { + /// # run(); + /// # } + /// # + /// # fn run() { /// # Bastion::init(); /// # /// # let sp_ref = Bastion::supervisor(|sp| sp).unwrap(); @@ -1729,6 +1934,7 @@ impl SupervisorRef { /// # Bastion::start(); /// # Bastion::stop(); /// # Bastion::block_until_stopped(); + /// # } /// ``` pub fn kill(&self) -> Result<(), ()> { debug!("SupervisorRef({}): Killing.", self.id()); From 828b5219462de422fdde3533b9c686049aedfdbd Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 31 Jan 2021 21:37:59 +0100 Subject: [PATCH 09/12] runtime-tokio => tokio-runtime --- src/bastion-executor/Cargo.toml | 2 +- src/bastion-executor/src/blocking.rs | 10 +-- src/bastion-executor/src/pool.rs | 14 ++-- src/bastion-executor/tests/lib.rs | 4 +- src/bastion-executor/tests/run_blocking.rs | 4 +- src/bastion/Cargo.toml | 2 +- src/bastion/examples/hello_tokio.rs | 10 +-- src/bastion/src/bastion.rs | 44 ++++++------- src/bastion/src/callbacks.rs | 24 +++---- src/bastion/src/child_ref.rs | 24 +++---- src/bastion/src/children.rs | 32 +++++----- src/bastion/src/children_ref.rs | 24 +++---- src/bastion/src/config.rs | 12 ++-- src/bastion/src/context.rs | 48 +++++++------- src/bastion/src/envelope.rs | 20 +++--- src/bastion/src/executor.rs | 12 ++-- src/bastion/src/macros.rs | 20 +++--- src/bastion/src/message.rs | 16 ++--- src/bastion/src/path.rs | 24 +++---- src/bastion/src/supervisor.rs | 64 +++++++++---------- src/bastion/tests/message_signatures.rs | 4 +- src/bastion/tests/prop_children_broadcast.rs | 4 +- src/bastion/tests/prop_children_message.rs | 4 +- src/bastion/tests/prop_children_redundancy.rs | 4 +- src/bastion/tests/run_blocking.rs | 4 +- src/bastion/tests/tokio_runtime.rs | 2 +- 26 files changed, 216 insertions(+), 216 deletions(-) diff --git a/src/bastion-executor/Cargo.toml b/src/bastion-executor/Cargo.toml index fd25cce2..58fa8150 100644 --- a/src/bastion-executor/Cargo.toml +++ b/src/bastion-executor/Cargo.toml @@ -26,7 +26,7 @@ maintenance = { status = "actively-developed" } [features] unstable = [] -runtime-tokio = ["tokio"] +tokio-runtime = ["tokio"] [dependencies] # lightproc = "0.3.5" diff --git a/src/bastion-executor/src/blocking.rs b/src/bastion-executor/src/blocking.rs index d26dd377..790e15ae 100644 --- a/src/bastion-executor/src/blocking.rs +++ b/src/bastion-executor/src/blocking.rs @@ -41,7 +41,7 @@ struct BlockingRunner { // We keep a handle to the tokio runtime here to make sure // it will never be dropped while the DynamicPoolManager is alive, // In case we need to spin up some threads. - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] runtime_handle: tokio::runtime::Handle, } @@ -80,11 +80,11 @@ impl DynamicRunner for BlockingRunner { impl BlockingRunner { fn run(&self, task: LightProc) { - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] { self.runtime_handle.spawn_blocking(|| task.run()); } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] { task.run(); } @@ -100,7 +100,7 @@ struct Pool { static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] { let runner = Arc::new(BlockingRunner { // We use current() here instead of try_current() @@ -113,7 +113,7 @@ static POOL: Lazy = Lazy::new(|| { .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) .expect("couldn't create dynamic pool manager"); } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] { let runner = Arc::new(BlockingRunner {}); diff --git a/src/bastion-executor/src/pool.rs b/src/bastion-executor/src/pool.rs index bc84bb3f..4ab64cad 100644 --- a/src/bastion-executor/src/pool.rs +++ b/src/bastion-executor/src/pool.rs @@ -27,13 +27,13 @@ use tracing::trace; /// use bastion_executor::prelude::*; /// use lightproc::prelude::*; /// -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # start(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # start(); /// # } @@ -151,7 +151,7 @@ struct AsyncRunner { // We keep a handle to the tokio runtime here to make sure // it will never be dropped while the DynamicPoolManager is alive, // In case we need to spin up some threads. - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] runtime_handle: tokio::runtime::Handle, } @@ -190,11 +190,11 @@ impl DynamicRunner for AsyncRunner { impl AsyncRunner { fn run(&self, task: LightProc) { - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] { self.runtime_handle.spawn_blocking(|| task.run()); } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] { task.run(); } @@ -204,7 +204,7 @@ impl AsyncRunner { static DYNAMIC_POOL_MANAGER: OnceCell = OnceCell::new(); static POOL: Lazy = Lazy::new(|| { - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] { let runner = Arc::new(AsyncRunner { // We use current() here instead of try_current() @@ -217,7 +217,7 @@ static POOL: Lazy = Lazy::new(|| { .set(DynamicPoolManager::new(*low_watermark() as usize, runner)) .expect("couldn't create dynamic pool manager"); } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] { let runner = Arc::new(AsyncRunner {}); diff --git a/src/bastion-executor/tests/lib.rs b/src/bastion-executor/tests/lib.rs index 8d87ca9c..416c571c 100644 --- a/src/bastion-executor/tests/lib.rs +++ b/src/bastion-executor/tests/lib.rs @@ -8,7 +8,7 @@ mod tests { dbg!(core_ids); } - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] mod tokio_tests { #[tokio::test] async fn pool_check() { @@ -16,7 +16,7 @@ mod tests { } } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] mod no_tokio_tests { #[test] fn pool_check() { diff --git a/src/bastion-executor/tests/run_blocking.rs b/src/bastion-executor/tests/run_blocking.rs index a454b906..6f792957 100644 --- a/src/bastion-executor/tests/run_blocking.rs +++ b/src/bastion-executor/tests/run_blocking.rs @@ -4,7 +4,7 @@ use lightproc::proc_stack::ProcStack; use std::thread; use std::time::Duration; -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_tests { #[tokio::test] async fn test_run_blocking() { @@ -12,7 +12,7 @@ mod tokio_tests { } } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] mod no_tokio_tests { #[test] fn test_run_blocking() { diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index a5d9fa2f..fa6f305d 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -43,7 +43,7 @@ distributed = [ ] scaling = [] docs = ["distributed", "scaling", "default"] -runtime-tokio = ["bastion-executor/runtime-tokio"] +tokio-runtime = ["bastion-executor/tokio-runtime"] [package.metadata.docs.rs] features = ["docs"] diff --git a/src/bastion/examples/hello_tokio.rs b/src/bastion/examples/hello_tokio.rs index e11f906f..57792867 100644 --- a/src/bastion/examples/hello_tokio.rs +++ b/src/bastion/examples/hello_tokio.rs @@ -1,10 +1,10 @@ use anyhow::Result as AnyResult; use bastion::prelude::*; -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] use tokio; use tracing::{error, warn, Level}; -/// `cargo run --features=runtime-tokio --example hello_tokio` +/// `cargo run --features=tokio-runtime --example hello_tokio` /// /// We are focusing on the contents of the msg! macro here. /// If you would like to understand how the rest works, @@ -24,7 +24,7 @@ use tracing::{error, warn, Level}; /// Jan 31 14:56:03.683 WARN hello_tokio: let's sleep for 10 seconds within a spawn block /// Jan 31 14:56:13.683 WARN hello_tokio: the spawn! is complete /// Jan 31 14:56:15.679 WARN hello_tokio: we're done, stopping the bastion! -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] #[tokio::main] async fn main() -> AnyResult<()> { // Initialize tracing logger @@ -95,7 +95,7 @@ async fn main() -> AnyResult<()> { Ok(()) } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] fn main() { - panic!("this example requires the runtime-tokio feature: `cargo run --features=runtime-tokio --example hello_tokio`") + panic!("this example requires the tokio-runtime feature: `cargo run --features=tokio-runtime --example hello_tokio`") } diff --git a/src/bastion/src/bastion.rs b/src/bastion/src/bastion.rs index b57d9b24..c9969005 100644 --- a/src/bastion/src/bastion.rs +++ b/src/bastion/src/bastion.rs @@ -29,13 +29,13 @@ distributed_api! { /// ```rust /// use bastion::prelude::*; /// -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -183,13 +183,13 @@ impl Bastion { /// # Example /// /// ```rust - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -230,13 +230,13 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -285,13 +285,13 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -357,13 +357,13 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -420,13 +420,13 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -486,13 +486,13 @@ impl Bastion { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -546,13 +546,13 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -588,13 +588,13 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -631,13 +631,13 @@ impl Bastion { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -680,13 +680,13 @@ impl Bastion { /// # Example /// /// ```rust - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/callbacks.rs b/src/bastion/src/callbacks.rs index 18cef852..91e9dcb8 100644 --- a/src/bastion/src/callbacks.rs +++ b/src/bastion/src/callbacks.rs @@ -19,13 +19,13 @@ pub(crate) enum CallbackType { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -74,13 +74,13 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -133,13 +133,13 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -205,13 +205,13 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -279,13 +279,13 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -357,13 +357,13 @@ impl Callbacks { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/child_ref.rs b/src/bastion/src/child_ref.rs index 51520c3c..0dcfedf3 100644 --- a/src/bastion/src/child_ref.rs +++ b/src/bastion/src/child_ref.rs @@ -67,13 +67,13 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -111,13 +111,13 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -161,13 +161,13 @@ impl ChildRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -232,13 +232,13 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -325,13 +325,13 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -384,13 +384,13 @@ impl ChildRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/children.rs b/src/bastion/src/children.rs index e0474e4a..b9f20009 100644 --- a/src/bastion/src/children.rs +++ b/src/bastion/src/children.rs @@ -49,13 +49,13 @@ use tracing::{debug, trace, warn}; /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -170,13 +170,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -270,13 +270,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -329,13 +329,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -388,13 +388,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -434,13 +434,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -485,13 +485,13 @@ impl Children { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -547,13 +547,13 @@ impl Children { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/children_ref.rs b/src/bastion/src/children_ref.rs index af7a8c6e..00173023 100644 --- a/src/bastion/src/children_ref.rs +++ b/src/bastion/src/children_ref.rs @@ -52,13 +52,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -90,13 +90,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -126,13 +126,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -174,13 +174,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -241,13 +241,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -282,13 +282,13 @@ impl ChildrenRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/config.rs b/src/bastion/src/config.rs index fe6c4f2e..d784235a 100644 --- a/src/bastion/src/config.rs +++ b/src/bastion/src/config.rs @@ -10,13 +10,13 @@ /// ```rust /// use bastion::prelude::*; /// -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -70,13 +70,13 @@ impl Config { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -109,13 +109,13 @@ impl Config { /// ```rust /// use bastion::prelude::*; /// - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/context.rs b/src/bastion/src/context.rs index b5713622..4f01339f 100644 --- a/src/bastion/src/context.rs +++ b/src/bastion/src/context.rs @@ -42,13 +42,13 @@ pub const NIL_ID: BastionId = BastionId(Uuid::nil()); /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -84,13 +84,13 @@ pub struct BastionId(pub(crate) Uuid); /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -181,13 +181,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -226,13 +226,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -274,13 +274,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -348,13 +348,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -417,13 +417,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -481,13 +481,13 @@ impl BastionContext { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -543,13 +543,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -594,13 +594,13 @@ impl BastionContext { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -659,13 +659,13 @@ impl BastionContext { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -840,7 +840,7 @@ mod context_tests { use crate::Bastion; use std::panic; - #[cfg(feature = "runtime-tokio")] + #[cfg(feature = "tokio-runtime")] mod tokio_tests { #[tokio::test] async fn test_context() { @@ -848,7 +848,7 @@ mod context_tests { } } - #[cfg(not(feature = "runtime-tokio"))] + #[cfg(not(feature = "tokio-runtime"))] mod no_tokio_tests { #[test] fn test_context() { diff --git a/src/bastion/src/envelope.rs b/src/bastion/src/envelope.rs index 6060c516..a08c5d1f 100644 --- a/src/bastion/src/envelope.rs +++ b/src/bastion/src/envelope.rs @@ -22,13 +22,13 @@ pub(crate) struct Envelope { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -73,13 +73,13 @@ impl SignedMessage { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -115,13 +115,13 @@ impl SignedMessage { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -173,13 +173,13 @@ impl RefAddr { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -224,13 +224,13 @@ impl RefAddr { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/executor.rs b/src/bastion/src/executor.rs index 2c052a71..cd8ef5cd 100644 --- a/src/bastion/src/executor.rs +++ b/src/bastion/src/executor.rs @@ -10,13 +10,13 @@ use std::future::Future; /// # Example /// ``` /// # use std::{thread, time}; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -42,13 +42,13 @@ where /// # Example /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -84,13 +84,13 @@ where /// # Example /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/macros.rs b/src/bastion/src/macros.rs index 9bb64b7c..d577075e 100644 --- a/src/bastion/src/macros.rs +++ b/src/bastion/src/macros.rs @@ -8,13 +8,13 @@ /// /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -144,13 +144,13 @@ macro_rules! children { /// # Example /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -211,13 +211,13 @@ macro_rules! supervisor { /// # use std::{thread, time}; /// # use lightproc::proc_stack::ProcStack; /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -244,13 +244,13 @@ macro_rules! blocking { /// # Example /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -289,13 +289,13 @@ macro_rules! run { /// # Example /// ``` /// # use bastion::prelude::*; -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/message.rs b/src/bastion/src/message.rs index b50fcdaf..cba09d79 100644 --- a/src/bastion/src/message.rs +++ b/src/bastion/src/message.rs @@ -49,13 +49,13 @@ pub struct AnswerSender(oneshot::Sender); /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -136,13 +136,13 @@ pub struct Answer(Receiver); /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -594,13 +594,13 @@ impl Future for Answer { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -809,13 +809,13 @@ macro_rules! msg { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/path.rs b/src/bastion/src/path.rs index 82492bad..1c9011c3 100644 --- a/src/bastion/src/path.rs +++ b/src/bastion/src/path.rs @@ -17,13 +17,13 @@ use std::result::Result; /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -83,13 +83,13 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -135,13 +135,13 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -187,13 +187,13 @@ impl BastionPath { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -307,13 +307,13 @@ impl fmt::Debug for BastionPath { /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -390,13 +390,13 @@ impl BastionPathElement { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/src/supervisor.rs b/src/bastion/src/supervisor.rs index 39d16c9d..8000ab52 100644 --- a/src/bastion/src/supervisor.rs +++ b/src/bastion/src/supervisor.rs @@ -44,13 +44,13 @@ use tracing::{debug, trace, warn}; /// ```rust /// # use bastion::prelude::*; /// # -/// # #[cfg(feature = "runtime-tokio")] +/// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # -/// # #[cfg(not(feature = "runtime-tokio"))] +/// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -371,13 +371,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -440,13 +440,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -516,13 +516,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -594,13 +594,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -684,13 +684,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -786,13 +786,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -837,13 +837,13 @@ impl Supervisor { /// # use bastion::prelude::*; /// # use std::time::Duration; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -894,13 +894,13 @@ impl Supervisor { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1517,13 +1517,13 @@ impl SupervisorRef { /// ```rust /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1565,13 +1565,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1641,13 +1641,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1752,13 +1752,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1806,13 +1806,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1873,13 +1873,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } @@ -1914,13 +1914,13 @@ impl SupervisorRef { /// ``` /// # use bastion::prelude::*; /// # - /// # #[cfg(feature = "runtime-tokio")] + /// # #[cfg(feature = "tokio-runtime")] /// # #[tokio::main] /// # async fn main() { /// # run(); /// # } /// # - /// # #[cfg(not(feature = "runtime-tokio"))] + /// # #[cfg(not(feature = "tokio-runtime"))] /// # fn main() { /// # run(); /// # } diff --git a/src/bastion/tests/message_signatures.rs b/src/bastion/tests/message_signatures.rs index 2ac404db..8d3abe7f 100644 --- a/src/bastion/tests/message_signatures.rs +++ b/src/bastion/tests/message_signatures.rs @@ -42,7 +42,7 @@ fn spawn_responders() -> ChildrenRef { .expect("Couldn't create the children group.") } -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_tests { use super::*; @@ -54,7 +54,7 @@ mod tokio_tests { } } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] mod no_tokio_tests { use super::*; diff --git a/src/bastion/tests/prop_children_broadcast.rs b/src/bastion/tests/prop_children_broadcast.rs index 4d2b8e13..4da349e1 100644 --- a/src/bastion/tests/prop_children_broadcast.rs +++ b/src/bastion/tests/prop_children_broadcast.rs @@ -4,7 +4,7 @@ use std::sync::Once; static START: Once = Once::new(); -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_proptests { use super::*; proptest! { @@ -18,7 +18,7 @@ mod tokio_proptests { } } } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] mod not_tokio_proptests { use super::*; diff --git a/src/bastion/tests/prop_children_message.rs b/src/bastion/tests/prop_children_message.rs index 4eaa7d4f..d6278fb1 100644 --- a/src/bastion/tests/prop_children_message.rs +++ b/src/bastion/tests/prop_children_message.rs @@ -5,7 +5,7 @@ use std::sync::Once; static START: Once = Once::new(); -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_proptests { use super::*; proptest! { @@ -20,7 +20,7 @@ mod tokio_proptests { } } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] mod not_tokio_proptests { use super::*; diff --git a/src/bastion/tests/prop_children_redundancy.rs b/src/bastion/tests/prop_children_redundancy.rs index 59882654..4354d47f 100644 --- a/src/bastion/tests/prop_children_redundancy.rs +++ b/src/bastion/tests/prop_children_redundancy.rs @@ -5,8 +5,8 @@ use std::sync::Once; static START: Once = Once::new(); -// TODO [igni]: Figure out how to make it work with feature = "runtime-tokio" -#[cfg(not(feature = "runtime-tokio"))] +// TODO [igni]: Figure out how to make it work with feature = "tokio-runtime" +#[cfg(not(feature = "tokio-runtime"))] mod not_tokio_proptests { use super::*; diff --git a/src/bastion/tests/run_blocking.rs b/src/bastion/tests/run_blocking.rs index 1ebbd596..00ff3908 100644 --- a/src/bastion/tests/run_blocking.rs +++ b/src/bastion/tests/run_blocking.rs @@ -6,7 +6,7 @@ use std::sync::{ use std::thread; use std::time::Duration; -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_tests { #[tokio::test] async fn test_run_blocking() { @@ -14,7 +14,7 @@ mod tokio_tests { } } -#[cfg(not(feature = "runtime-tokio"))] +#[cfg(not(feature = "tokio-runtime"))] mod not_tokio_tests { #[test] fn test_run_blocking() { diff --git a/src/bastion/tests/tokio_runtime.rs b/src/bastion/tests/tokio_runtime.rs index 64784da3..4e7408c4 100644 --- a/src/bastion/tests/tokio_runtime.rs +++ b/src/bastion/tests/tokio_runtime.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "runtime-tokio")] +#[cfg(feature = "tokio-runtime")] mod tokio_tests { use bastion::prelude::*; From 951254896348121de4529fc54c3fe43efcd1fc50 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Mon, 1 Feb 2021 18:43:39 +0100 Subject: [PATCH 10/12] tokio_test is amazing <3 --- src/bastion-executor/Cargo.toml | 2 + src/bastion-executor/benches/blocking.rs | 34 ++++++++++-- src/bastion-executor/benches/run_blocking.rs | 53 +++++++++++++------ src/bastion-executor/benches/spawn.rs | 34 ++++++++++-- src/bastion/Cargo.toml | 3 +- src/bastion/tests/prop_children_broadcast.rs | 3 +- src/bastion/tests/prop_children_redundancy.rs | 17 +++++- 7 files changed, 117 insertions(+), 29 deletions(-) diff --git a/src/bastion-executor/Cargo.toml b/src/bastion-executor/Cargo.toml index 34011a80..dc3bee30 100644 --- a/src/bastion-executor/Cargo.toml +++ b/src/bastion-executor/Cargo.toml @@ -57,6 +57,8 @@ tokio = {version = "1.1", features = ["rt", "rt-multi-thread"], optional = true winapi = { version = "^0.3.8", features = ["basetsd"] } [dev-dependencies] +tokio = {version = "1.1", features = ["rt", "rt-multi-thread", "macros"] } +tokio-test = "0.4.0" proptest = "^0.10" futures = "0.3.5" tracing-subscriber = "0.2.11" diff --git a/src/bastion-executor/benches/blocking.rs b/src/bastion-executor/benches/blocking.rs index aef5e1fc..a7b6e7f3 100644 --- a/src/bastion-executor/benches/blocking.rs +++ b/src/bastion-executor/benches/blocking.rs @@ -8,9 +8,36 @@ use std::thread; use std::time::Duration; use test::Bencher; +#[cfg(feature = "tokio-runtime")] +mod tokio_benchs { + use super::*; + #[bench] + fn blocking(b: &mut Bencher) { + tokio_test::block_on(async { _blocking(b) }); + } + #[bench] + fn blocking_single(b: &mut Bencher) { + tokio_test::block_on(async { + _blocking_single(b); + }); + } +} + +#[cfg(not(feature = "tokio-runtime"))] +mod no_tokio_benchs { + use super::*; + #[bench] + fn blocking(b: &mut Bencher) { + _blocking(&mut b); + } + #[bench] + fn blocking_single(b: &mut Bencher) { + _blocking_single(&mut b); + } +} + // Benchmark for a 10K burst task spawn -#[bench] -fn blocking(b: &mut Bencher) { +fn _blocking(b: &mut Bencher) { b.iter(|| { (0..10_000) .map(|_| { @@ -27,8 +54,7 @@ fn blocking(b: &mut Bencher) { } // Benchmark for a single blocking task spawn -#[bench] -fn blocking_single(b: &mut Bencher) { +fn _blocking_single(b: &mut Bencher) { b.iter(|| { blocking::spawn_blocking( async { diff --git a/src/bastion-executor/benches/run_blocking.rs b/src/bastion-executor/benches/run_blocking.rs index d6fa4dcc..dc1053c3 100644 --- a/src/bastion-executor/benches/run_blocking.rs +++ b/src/bastion-executor/benches/run_blocking.rs @@ -10,11 +10,38 @@ use std::thread; use std::time::Duration; use test::Bencher; +#[cfg(feature = "tokio-runtime")] +mod tokio_benchs { + use super::*; + #[bench] + fn blocking(b: &mut Bencher) { + tokio_test::block_on(async { _blocking(b) }); + } + #[bench] + fn blocking_single(b: &mut Bencher) { + tokio_test::block_on(async { + _blocking_single(b); + }); + } +} + +#[cfg(not(feature = "tokio-runtime"))] +mod no_tokio_benchs { + use super::*; + #[bench] + fn blocking(b: &mut Bencher) { + _blocking(&mut b); + } + #[bench] + fn blocking_single(b: &mut Bencher) { + _blocking_single(&mut b); + } +} + // Benchmark for a 10K burst task spawn -#[bench] -fn run_blocking(b: &mut Bencher) { +fn _blocking(b: &mut Bencher) { b.iter(|| { - let handles = (0..10_000) + (0..10_000) .map(|_| { blocking::spawn_blocking( async { @@ -24,24 +51,18 @@ fn run_blocking(b: &mut Bencher) { ProcStack::default(), ) }) - .collect::>(); - - run(join_all(handles), ProcStack::default()) + .collect::>() }); } // Benchmark for a single blocking task spawn -#[bench] -fn run_blocking_single(b: &mut Bencher) { +fn _blocking_single(b: &mut Bencher) { b.iter(|| { - run( - blocking::spawn_blocking( - async { - let duration = Duration::from_millis(1); - thread::sleep(duration); - }, - ProcStack::default(), - ), + blocking::spawn_blocking( + async { + let duration = Duration::from_millis(1); + thread::sleep(duration); + }, ProcStack::default(), ) }); diff --git a/src/bastion-executor/benches/spawn.rs b/src/bastion-executor/benches/spawn.rs index 7eefc62c..060ee187 100644 --- a/src/bastion-executor/benches/spawn.rs +++ b/src/bastion-executor/benches/spawn.rs @@ -9,9 +9,36 @@ use lightproc::proc_stack::ProcStack; use std::time::Duration; use test::Bencher; +#[cfg(feature = "tokio-runtime")] +mod tokio_benchs { + use super::*; + #[bench] + fn spawn_lot(b: &mut Bencher) { + tokio_test::block_on(async { _spawn_lot(b) }); + } + #[bench] + fn spawn_single(b: &mut Bencher) { + tokio_test::block_on(async { + _spawn_single(b); + }); + } +} + +#[cfg(not(feature = "tokio-runtime"))] +mod no_tokio_benchs { + use super::*; + #[bench] + fn spawn_lot(b: &mut Bencher) { + _spawn_lot(&mut b); + } + #[bench] + fn spawn_single(b: &mut Bencher) { + _spawn_single(&mut b); + } +} + // Benchmark for a 10K burst task spawn -#[bench] -fn spawn_lot(b: &mut Bencher) { +fn _spawn_lot(b: &mut Bencher) { let proc_stack = ProcStack::default(); b.iter(|| { let _ = (0..10_000) @@ -29,8 +56,7 @@ fn spawn_lot(b: &mut Bencher) { } // Benchmark for a single task spawn -#[bench] -fn spawn_single(b: &mut Bencher) { +fn _spawn_single(b: &mut Bencher) { let proc_stack = ProcStack::default(); b.iter(|| { spawn( diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index 815b05fe..7b12f2f2 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -92,4 +92,5 @@ num_cpus = "1.13.0" # hello_tokio example tokio = { version="1.1", features = ["time", "macros"] } bastion-executor = { path = "../bastion-executor" } -once_cell = "1.5.2" \ No newline at end of file +once_cell = "1.5.2" +tokio-test = "0.4.0" diff --git a/src/bastion/tests/prop_children_broadcast.rs b/src/bastion/tests/prop_children_broadcast.rs index 4da349e1..df072d81 100644 --- a/src/bastion/tests/prop_children_broadcast.rs +++ b/src/bastion/tests/prop_children_broadcast.rs @@ -11,9 +11,8 @@ mod tokio_proptests { #![proptest_config(ProptestConfig::with_cases(1_000))] #[test] fn proptest_bcast_message(message in "\\PC*") { - tokio::runtime::Runtime::new().unwrap().block_on(async { + tokio_test::block_on(async { super::test_with_message(message); - }); } } diff --git a/src/bastion/tests/prop_children_redundancy.rs b/src/bastion/tests/prop_children_redundancy.rs index 4354d47f..3d5ee508 100644 --- a/src/bastion/tests/prop_children_redundancy.rs +++ b/src/bastion/tests/prop_children_redundancy.rs @@ -1,11 +1,24 @@ use bastion::prelude::*; use proptest::prelude::*; -use std::sync::Arc; use std::sync::Once; static START: Once = Once::new(); -// TODO [igni]: Figure out how to make it work with feature = "tokio-runtime" +#[cfg(feature = "tokio-runtime")] +mod tokio_proptests { + use super::*; + + proptest! { + #![proptest_config(ProptestConfig::with_cases(1_000))] + #[test] + fn proptest_redundancy(r in std::usize::MIN..32) { + let _ = tokio_test::task::spawn(async { + super::test_with_usize(r); + }); + } + } +} + #[cfg(not(feature = "tokio-runtime"))] mod not_tokio_proptests { use super::*; From 5e5e449e0292c8cf6edf9d4cc89b40f0e7c7b991 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Mon, 1 Feb 2021 18:49:51 +0100 Subject: [PATCH 11/12] woopsie --- src/bastion-executor/benches/blocking.rs | 4 ++-- src/bastion-executor/benches/run_blocking.rs | 4 ++-- src/bastion-executor/benches/spawn.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bastion-executor/benches/blocking.rs b/src/bastion-executor/benches/blocking.rs index a7b6e7f3..6c5a6ffd 100644 --- a/src/bastion-executor/benches/blocking.rs +++ b/src/bastion-executor/benches/blocking.rs @@ -28,11 +28,11 @@ mod no_tokio_benchs { use super::*; #[bench] fn blocking(b: &mut Bencher) { - _blocking(&mut b); + _blocking(b); } #[bench] fn blocking_single(b: &mut Bencher) { - _blocking_single(&mut b); + _blocking_single(b); } } diff --git a/src/bastion-executor/benches/run_blocking.rs b/src/bastion-executor/benches/run_blocking.rs index dc1053c3..43de4400 100644 --- a/src/bastion-executor/benches/run_blocking.rs +++ b/src/bastion-executor/benches/run_blocking.rs @@ -30,11 +30,11 @@ mod no_tokio_benchs { use super::*; #[bench] fn blocking(b: &mut Bencher) { - _blocking(&mut b); + _blocking(b); } #[bench] fn blocking_single(b: &mut Bencher) { - _blocking_single(&mut b); + _blocking_single(b); } } diff --git a/src/bastion-executor/benches/spawn.rs b/src/bastion-executor/benches/spawn.rs index 060ee187..02b896bf 100644 --- a/src/bastion-executor/benches/spawn.rs +++ b/src/bastion-executor/benches/spawn.rs @@ -29,11 +29,11 @@ mod no_tokio_benchs { use super::*; #[bench] fn spawn_lot(b: &mut Bencher) { - _spawn_lot(&mut b); + _spawn_lot(b); } #[bench] fn spawn_single(b: &mut Bencher) { - _spawn_single(&mut b); + _spawn_single(b); } } From d9ee540255bc30b784468e96ceef97d5a4b157ff Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Mon, 1 Feb 2021 19:48:23 +0100 Subject: [PATCH 12/12] prepare for master, so we can beta test the tokio feature --- src/bastion/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bastion/Cargo.toml b/src/bastion/Cargo.toml index ea8e1504..0f8198d6 100644 --- a/src/bastion/Cargo.toml +++ b/src/bastion/Cargo.toml @@ -50,7 +50,7 @@ features = ["docs"] rustdoc-args = ["--cfg", "feature=\"docs\""] [dependencies] -bastion-executor = "0.4" +bastion-executor = { git = "https://github.com/bastion-rs/bastion.git" } lightproc = "0.3.5" # bastion-executor = { version = "= 0.3.7-alpha.0", path = "../bastion-executor" } # lightproc = { version = "= 0.3.6-alpha.0", path = "../lightproc" } @@ -91,6 +91,6 @@ rayon = "1.3.1" num_cpus = "1.13.0" # hello_tokio example tokio = { version="1.1", features = ["time", "macros"] } -bastion-executor = { path = "../bastion-executor" } +bastion-executor = { git = "https://github.com/bastion-rs/bastion.git" } once_cell = "1.5.2" tokio-test = "0.4.0"