use std::future::Future;
use std::thread;
fn run_on_cli_stack<T: Send + 'static>(name: &str, run: impl FnOnce() -> T + Send + 'static) -> T {
thread::Builder::new()
.name(name.into())
.stack_size(crate::CLI_RUNTIME_STACK_SIZE)
.spawn(run)
.expect("failed to spawn CLI-stack test thread")
.join()
.expect("CLI-stack test thread panicked")
}
pub fn block_on_cli_stack<Fut>(build: impl FnOnce() -> Fut + Send + 'static) -> Fut::Output
where
Fut: Future + 'static,
Fut::Output: Send + 'static,
{
run_on_cli_stack("harn-cli-test", move || {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("CLI test runtime")
.block_on(build())
})
}
pub fn block_on_cli_stack_multi_thread<Fut>(
build: impl FnOnce() -> Fut + Send + 'static,
) -> Fut::Output
where
Fut: Future + 'static,
Fut::Output: Send + 'static,
{
run_on_cli_stack("harn-cli-test", move || {
tokio::runtime::Builder::new_multi_thread()
.thread_stack_size(crate::CLI_RUNTIME_STACK_SIZE)
.enable_all()
.build()
.expect("multi-thread CLI test runtime")
.block_on(build())
})
}