https://github.com/durch/block_on
Generate a blocking method for each async method in an impl block. Supports either `tokio` or `async-std` backend.
https://github.com/durch/block_on
Last synced: 3 months ago
JSON representation
Generate a blocking method for each async method in an impl block. Supports either `tokio` or `async-std` backend.
- Host: GitHub
- URL: https://github.com/durch/block_on
- Owner: durch
- License: mit
- Created: 2020-11-15T19:02:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-11T11:09:51.000Z (over 5 years ago)
- Last Synced: 2026-01-02T09:16:03.740Z (6 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## block_on proc macro
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`.
### Example `tokio`
```rust
// Requires tokio rt and rt-multi-thread features
use block_on::block_on;
struct Tokio {}
#[block_on("tokio")]
impl Tokio {
async fn test_async(&self) {}
}
```
Generates the following impl block
```rust
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())
}
```
### Example `async-std`
```rust
use 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
```rust
async fn test_async(&self) {}
fn test_async_blocking(&self) {
use async_std::task;
task::block_on(self.test_async())
}
```