SkillAgentSearch skills...

Enjoin

syntax-level async join enabling branching control flow and shared mutable borrow

Install / Use

/learn @wishawa/Enjoin
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

enjoin

<img alt="on crates.io" src="https://img.shields.io/crates/v/enjoin?style=for-the-badge" height="20"> <img alt="on docs.rs" src="https://img.shields.io/docsrs/enjoin?style=for-the-badge" height="20">

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.

View on GitHub
GitHub Stars27
CategoryDevelopment
Updated2y ago
Forks0

Languages

Rust

Security Score

60/100

Audited on Jun 7, 2023

No findings