Skip to main content
Module

x/dpp_vim/deps.ts>Lock

Dark powered plugin manager for Vim/neovim
Latest
class Lock
import { Lock } from "https://deno.land/x/dpp_vim@v0.2.0/deps.ts";

A mutual exclusion lock that provides safe concurrent access to a shared value.

import { AsyncValue } from "https://deno.land/x/async@v0.2.0/testutil.ts";
import { Lock } from "https://deno.land/x/async@v0.2.0/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.

Properties

readonly
locked: boolean

Returns true if the lock is currently locked, false otherwise.

Methods

lock<R>(f: (value: T) => R | PromiseLike<R>): Promise<R>

Acquires the lock and applies the given function to the shared value, returning the result.