#proc #block #ui #async #tokio #async-std #proc-block

macro block_on_proc

Generate a blocking method for each async method in an impl block. Supports either tokio or async-std backend.

2 unstable releases

0.2.0 Jan 11, 2021
0.1.0 Nov 15, 2020
Download history 2259/week @ 2023-06-06 2485/week @ 2023-06-13 2565/week @ 2023-06-20 2568/week @ 2023-06-27 2115/week @ 2023-07-04 2202/week @ 2023-07-11 2170/week @ 2023-07-18 2546/week @ 2023-07-25 1906/week @ 2023-08-01 2213/week @ 2023-08-08 2281/week @ 2023-08-15 1989/week @ 2023-08-22 2775/week @ 2023-08-29 4151/week @ 2023-09-05 2985/week @ 2023-09-12 2771/week @ 2023-09-19

13,189 downloads per month
Used in 5 crates (via rust-s3)

MIT license

10KB
129 lines

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

use 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())
}

Example async-std

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

async fn test_async(&self) {}        

fn test_async_blocking(&self) {
      use async_std::task;
      task::block_on(self.test_async())
}

Dependencies

~0.9–1.2MB
~30K SLoC