enjoin 0.2.0

Powerful syntax-level async join macro
Documentation
  • Coverage
  • 22.22%
    2 out of 9 items documented1 out of 6 items with examples
  • Size
  • Source code size: 27.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • wishawa/enjoin
    27 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wishawa

enjoin

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 join

for _ in 0..10 {
    enjoin::join!(
        {
            if do_thing_1().await {
                break;
            }
        },
        {
            if do_thing_2().await {
                continue;
            }
        }
    );
}

Use ? (try operator) in a join

async 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?;
        }
    );
}

Share mutable borrows accross a join

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