| Crates.io | enjoin |
| lib.rs | enjoin |
| version | 0.2.0 |
| created_at | 2023-04-12 02:43:13.509777+00 |
| updated_at | 2023-04-13 03:26:52.312847+00 |
| description | Powerful syntax-level async join macro |
| homepage | |
| repository | https://github.com/wishawa/enjoin |
| max_upload_size | |
| id | 836522 |
| size | 26,183 |
enjoin's async join macros operate at the syntax level. It allows you to...
break, continue, and return out of async code running in a joinfor _ in 0..10 {
enjoin::join!(
{
if do_thing_1().await {
break;
}
},
{
if do_thing_2().await {
continue;
}
}
);
}
? (try operator) in a joinasync fn fetch_and_save_both() -> Result<(), Box<dyn Error>> {
enjoin::join!(
{
let data = fetch_data_1().await?;
save_data(data).await?;
},
{
let data = fetch_data_2().await?;
save_data(data).await?;
}
);
}
... as long as the mutable borrows don't last across yield point / await point.
let mut count = 0;
enjoin::join_auto_borrow!(
{
loop {
incr_signal.next().await;
count += 1;
}
},
{
loop {
decr_signal.next().await;
count -= 1;
}
}
);
See my blog post here for motivations, working mechanism, comparison to other join macros, and more.