import { Lock } from "https://deno.land/x/ddu_vim@v1.13.0/deps.ts";
Implements a mutex lock for Promise. Not thread-safe.
A lock can be used to guarantee exclusive access to a shared resource.
Methods
acquire(): Promise<true>
Acuire the lock.
This method waits until the lock is unlocked, sets it to locked and returns true
.
When more than one coroutine is blocked in acquire()
waiting for the lock to be unlocked, only
one coroutine eventually proceeds.
Acquiring a lock is fair, the coroutine that proceeds will be the first coroutine that started waiting on the lock.
locked(): boolean
Return true
if the lock is locked.
release(): void
Release the lock.
When the lock is locked, reset it to unlocked and return.
If the lock is unlocked, an Error is thrown.
with(callback: () => void | Promise<void>): Promise<void>
Acuire the lock and execute callback to access shared state.
This is preferred way to use a Lock.