Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/willow/src/store/mutex.ts>default

A Willow Data Model and Willow General Purpose Sync protocol implementation in TypeScript.
Latest
class default
import { default } from "https://deno.land/x/willow@0.3.5/src/store/mutex.ts";

A mutex lock for coordination across async functions This is based off of https://github.com/ide/await-lock/blob/master/src/AwaitLock.ts

Properties

private
acquired: boolean
private
currentMutexId: MutexId | null
private
waitingResolvers: Resolver[]

Methods

acquire(): Promise<MutexId>

Acquires the mutex, waiting if necessary for it to become free if it is already locked. The returned promise is fulfilled once the lock is acquired.

After acquiring the lock, you must call release when you are done with it.

release(mutexId: MutexId): void

Releases the lock and gives it to the next waiting acquirer, if there is one. Each acquirer may release the lock exactly once. If the UUID passed in doesn't match the current lock holder this will throw an error.