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

x/ayonli_jsext/workerd/index.ts>lock

A JavaScript extension package for building strong and modern applications.
Latest
function lock
Re-export
import { lock } from "https://deno.land/x/ayonli_jsext@v0.9.72/workerd/index.ts";

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

Parameters

key: any

Returns

Promise<Mutex.Lock<undefined>>