Skip to main content
Home

Built and signed on GitHub Actions

A distributed lock for deno powered by K8s Leases.

This package works with Node.js, Deno
This package works with Node.js
This package works with Deno
JSR Score
100%
Published
10 months ago (0.2.0)

dk8slock

A distributed lock for deno (& other Js Runtimes) powered by K8s Leases.

Inspired by:

Quick Start

This uses the power of Disposeables to create a lock for the entire function.

Deno

import { disposeableLock } from "jsr:@brad-jones/dk8slock";

async function contentiousFunc() {
  await using _ = await disposeableLock("MyLock");
  // Anything you do here is guaranteed to be only executing by a single worker.
}

Node.js

Install the node package with your favorite package manager.
npm used here but pnpm, yarn & others all work in much the same way.

npm install @brad-jones/dk8slock

NB: Don't attempt to use the JSR package with Node.js it will not work!

Known Issues

  • @cloudydeno/kubernetes-client leaks resources, it doesn't seem to close HttpClients.

    error: Leaks detected:
    - An HTTP client was created during the test, but not closed during the test. Close the HTTP client by calling `httpClient.close()`.
    

    Hence why our tests currently set sanitizeResources: false

Built and signed on
GitHub Actions

New Ticket: 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:@brad-jones/dk8slock

Import symbol

import * as dk_slock from "@brad-jones/dk8slock";
or

Import directly with a jsr specifier

import * as dk_slock from "jsr:@brad-jones/dk8slock";

Add Package

pnpm i jsr:@brad-jones/dk8slock
or (using pnpm 10.8 or older)
pnpm dlx jsr add @brad-jones/dk8slock

Import symbol

import * as dk_slock from "@brad-jones/dk8slock";

Add Package

yarn add jsr:@brad-jones/dk8slock
or (using Yarn 4.8 or older)
yarn dlx jsr add @brad-jones/dk8slock

Import symbol

import * as dk_slock from "@brad-jones/dk8slock";

Add Package

vlt install jsr:@brad-jones/dk8slock

Import symbol

import * as dk_slock from "@brad-jones/dk8slock";

Add Package

npx jsr add @brad-jones/dk8slock

Import symbol

import * as dk_slock from "@brad-jones/dk8slock";