import { Lock } from "https://deno.land/x/ddc_vim@v3.8.0/deps.ts";
A mutual exclusion lock that provides safe concurrent access to a shared value.
import { AsyncValue } from "./testutil.ts";
import { Lock } from "./lock.ts";
// Critical section
const count = new Lock(new AsyncValue(0));
await count.lock(async (count) => {
const v = await count.get();
count.set(v + 1);
});
Constructors
new
Lock(value: T)Constructs a new lock with the given initial value.