Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score88%
Published7 months ago (0.1.4)

Locking primitives for TypeScript

Locking primitives for TypeScript

This module provides various locking primitives for modern TypeScript:

import {Semaphore} from "@mdekstrand/locks";
const lock = new Semaphore(2);

function myContentiousTask() {
    using _lock = await lock.acquire();
    // do the work
    // the lock is automatically released at end of function!
}

It is heavily inspired by asyncutil, particularly in its API, with my own take on the ideas and a focus on simplicity and safety over extremes in performance (but it does try to avoid unnecessarily inefficient constructs).

It has a single dependency — deque, a TypeScript port of denque, used to implement Notify (which in turn is used to implement many other elements).

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";
or

Import directly with a jsr specifier

import * as locks from "jsr:@mdekstrand/locks";

Add Package

pnpm i jsr:@mdekstrand/locks
or (using pnpm 10.8 or older)
pnpm dlx jsr add @mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";

Add Package

yarn add jsr:@mdekstrand/locks
or (using Yarn 4.8 or older)
yarn dlx jsr add @mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";

Add Package

vlt install jsr:@mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";

Add Package

npx jsr add @mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";

Add Package

bunx jsr add @mdekstrand/locks

Import symbol

import * as locks from "@mdekstrand/locks";