1 //! Entry points for use with async_std runtimes.
2 pub use crate::impls::async_std::create_runtime as create_async_std_runtime;
3 use crate::{Runtime, SpawnBlocking};
4 
5 /// Return a new async-std-based [`Runtime`].
6 ///
7 /// Generally you should call this function only once, and then use
8 /// [`Clone::clone()`] to create additional references to that
9 /// runtime.
10 
create_runtime() -> std::io::Result<impl Runtime>11 pub fn create_runtime() -> std::io::Result<impl Runtime> {
12     Ok(create_async_std_runtime())
13 }
14 
15 /// Try to return an instance of the currently running async_std
16 /// [`Runtime`].
current_runtime() -> std::io::Result<impl Runtime>17 pub fn current_runtime() -> std::io::Result<impl Runtime> {
18     // In async_std, the runtime is a global singleton.
19     create_runtime()
20 }
21 
22 /// Run a test function using a freshly created async_std runtime.
test_with_runtime<P, F, O>(func: P) -> O where P: FnOnce(async_executors::AsyncStd) -> F, F: futures::Future<Output = O>,23 pub fn test_with_runtime<P, F, O>(func: P) -> O
24 where
25     P: FnOnce(async_executors::AsyncStd) -> F,
26     F: futures::Future<Output = O>,
27 {
28     let runtime = create_async_std_runtime();
29     runtime.block_on(func(runtime))
30 }
31