Crate nonparallel_async

Source
Expand description

A procedural macro for Rust that allows you to ensure that functions (e.g. unit tests) are not running at the same time.

This is achieved by acquiring a mutex at the beginning of the annotated function.

Different functions can synchronize on different mutexes. That’s why a static mutex reference must be passed to the nonparallel annotation.

§Usage

use tokio::sync::Mutex;
use nonparallel_async::nonparallel_async;

// Create two locks
static MUT_A: Mutex<()> = Mutex::const_new(());
static MUT_B: Mutex<()> = Mutex::const_new(());

// Mutually exclude parallel runs of functions using those two locks

#[nonparallel_async(MUT_A)]
async fn function_a1() {
    // This will not run in parallel to function_a2
}

#[nonparallel_async(MUT_A)]
async fn function_a2() {
    // This will not run in parallel to function_a1
}

#[nonparallel_async(MUT_B)]
async fn function_b() {
    // This may run in parallel to function_a*
}

Attribute Macros§

nonparallel_async