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

Overview

enjoin

on crates.io on docs.rs

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.

You might also like...
A simplistic functional programming language based around Lisp syntax.

Orchid A simplistic functional programming language based around Lisp syntax. Short taste # function to return the larger list (fn larger-list (as bs)

Oxido is a dynamic interpreted programming language basing most of its syntax on Rust.

Oxido Table of Contents: Oxido Installation Uninstallation Usage Syntax Data types Variables Reassignments Printing If statements Loop statements Func

An actors library for Rust and Tokio designed to work with async / await message handlers out of the box.

Akt An actors framework for Rust and Tokio. It is heavily inspired by Actix and right now it has very similar look and feel. The main difference is th

Low-level CPU and register abstractions for the N64 console

Description This crate is a low-level abstraction (aka a Peripheral Access Crate) over the CPU and memory-mapped registers available on the Nintendo 6

🎮 game loop + 🐷 coroutine + 🌯 burrito = 🚀🔥 blazingly synchronous async executor for games 🔥🚀
🎮 game loop + 🐷 coroutine + 🌯 burrito = 🚀🔥 blazingly synchronous async executor for games 🔥🚀

🐷 Koryto 🐷 Pronounced like corrito, which is pronounced as if you combined coroutine and burrito, because everyone knows coroutines are burritos in

Code accompanying the 1 Hour Dive into Async live stream.
Code accompanying the 1 Hour Dive into Async live stream.

1 Hour Async This is the code accompanying the 1 Hour Dive into Async live-stream. The slides are here You can watch the recorded event on YouTube Inc

Low level access to T-Head Xuantie RISC-V processors

XuanTie Low level access to T-Head XuanTie RISC-V processors Contributing We welcome contribution! Please send an issue or pull request if you are rea

 Gecko is a high-level, general-purpose programming language built on top of the LLVM project.
Gecko is a high-level, general-purpose programming language built on top of the LLVM project.

Gecko is a high-level, general-purpose programming language built on top of the LLVM project. Gecko Technology & principles Gecko is a general-purpose

Rust Imaging Library: A high-level Rust imaging crate.

ril Rust Imaging Library: A performant and high-level Rust imaging crate. Documentation • Crates.io • Discord What's this? This is a Rust crate design

Owner
Wisha W.
Wisha W.
A tool and library to losslessly join multiple .mp4 files shot with same camera and settings

mp4-merge A tool and library to losslessly join multiple .mp4 files shot with same camera and settings. This is useful to merge multiple files that ar

Gyroflow 7 Jan 2, 2023
🔀 Rusty flow graph processing library

flowing flowing is a flow graph processing library written in Rust. It shall serve as a general-purpose building block for all kinds of dataflow progr

Micha Hanselmann 2 Oct 4, 2022
Shared Channel for WebAssembly

Shared Channel for WebAssembly This crate provides a way for WebAssembly threads to receive messages from other threads using a JavaScript primitive c

wasm.rs 27 Nov 24, 2022
A small utility for modifying ELF shared library loading order.

elfpromote A small utility for modifying ELF shared library loading order. Usage $ cargo install elfpromote $ ldd blueboat_server linux-vdso.s

Heyang Zhou 5 Jul 21, 2022
A Simple Audio Control and Notifications Daemon

SACAND This is sacand, a Simple Audio Control and Notifications Daemon As it name oaths to imply, this is intended to be a simple audio control daemon

null 2 Jan 24, 2022
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

Domagoj Ratko 5 Nov 5, 2022
Control your .env like a boss

envctl ?? Take full control over your .env environment variables usage $ envctl --help Environment Variable Control Usage: envctl <COMMAND> Commands

Yuichiro Luke Smith 4 Apr 18, 2023
(early experiments toward) a version-control system for structured data

chit: (early experiments toward) a version-control system for structured data please note, very little is actually implemented here. this is not usefu

davidad (David A. Dalrymple) 3 Jul 24, 2023
A minimal `syn` syntax tree pretty-printer

prettyplease::unparse A minimal syn syntax tree pretty-printer. Overview This is a pretty-printer to turn a syn syntax tree into a String of well-form

David Tolnay 429 Dec 28, 2022