| Crates.io | block_on_proc |
| lib.rs | block_on_proc |
| version | 0.2.0 |
| created_at | 2020-11-15 19:06:05.30209+00 |
| updated_at | 2021-01-11 11:06:00.140471+00 |
| description | Generate a blocking method for each async method in an impl block. Supports either `tokio` or `async-std` backend. |
| homepage | |
| repository | https://github.com/durch/block_on.git |
| max_upload_size | |
| id | 312653 |
| size | 10,656 |
Generate a blocking method for each async method in an impl block. Supports either tokio or async-std backend.
Generated methods are suffixed with _blocking.
tokiouse block_on::block_on;
struct Tokio {}
#[block_on("tokio")]
impl Tokio {
async fn test_async(&self) {}
}
Generates the following impl block
async fn test_async(&self) {}
fn test_async_blocking(&self) {
use tokio::runtime::Runtime;
let mut rt = Runtime::new().unwrap();
rt.block_on(self.test_async())
}
async-stduse block_on::block_on;
struct AsyncStd {}
#[block_on("async-std")]
impl AsyncStd {
async fn test_async(&self) {}
}
Generates the following method in the same impl block
async fn test_async(&self) {}
fn test_async_blocking(&self) {
use async_std::task;
task::block_on(self.test_async())
}