import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/lock.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
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.
}
Returns
Promise<Mutex.Lock<undefined>>