Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/lock.js>default

A JavaScript extension package for building strong and modern applications.
Latest
function default
import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/lock.js";

Acquires a mutex lock for the given key in order to perform concurrent operations and prevent conflicts.

If the key is currently being locked by other coroutines, this function will block until the lock becomes available again.

Examples

Example 1

import lock from "@ayonli/jsext/lock";

const key = "lock_key";

export async function concurrentOperation() {
    using ctx = await lock(key);
    void ctx;

    // This block will never be run if there are other coroutines holding
    // the lock.
    //
    // Other coroutines trying to lock the same key will also never be run
    // before this function completes.
}