class DistributedLockObjectCore
Since 0.2.0

Serializes lock acquisition for one key.

One Durable Object per lock key, and a Durable Object executes one request at a time — which is what makes the read-compare-write below atomic without a transaction, and what makes this a genuine distributed lock rather than a best-effort one.

The holder record lives in state.storage, never in a field. A Durable Object is evicted after 70–140 seconds of inactivity when it cannot hibernate, and a lock TTL routinely outlives that; a deadline held in memory would evaporate on eviction and hand the same lock to a second holder, which is precisely the failure a distributed lock exists to prevent.

Examples

Example 1

import { DurableObject } from 'cloudflare:workers';
import { DistributedLockObjectCore } from '@setu-ts/cloudflare-plugin';

export class DistributedLockObject extends DurableObject {
  #core = new DistributedLockObjectCore(this.ctx);

  override fetch(request: Request): Promise<Response> {
    return this.#core.fetch(request);
  }
}

Constructors

DistributedLockObjectCore()
Parameters

The Durable Object's ctx

Optional seams; the defaults are the deployment path

Methods

fetch(request: Request): Promise<Response>

Routes one lock operation.

Usage

import { DistributedLockObjectCore } from "cloudflare-plugin/src/index.ts";