Skip to content
/ block_on Public

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

License

Notifications You must be signed in to change notification settings

durch/block_on

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

// 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

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages