method DurableObjectLock.prototype.acquire
DurableObjectLock.prototype.acquire(
key: string,
ttlMs: number
): Promise<string | null>

Attempts to acquire the lock.

Parameters

key: string

The lock key

ttlMs: number

How long the claim lasts, in milliseconds

Return Type

Promise<string | null>

The token when acquired, or null when another holder is live

Throws

CloudflareUnsupportedError

When the Durable Object answers with a non-2xx status — a misconfigured binding or a class that is not the lock object, neither of which may be reported as "someone else holds it"

Usage

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