alepha@docs:~/docs/reference/primitives$
cat $lock.md1 min read
#$lock
#Import
typescript
1import { $lock } from "alepha/lock";
#Overview
Distributed lock middleware for use arrays in $action, $job, $page, $pipeline.
Acquires a distributed lock before the handler runs and releases it after completion.
Throws LockAcquireError if the lock cannot be acquired (unless wait: true).
ts
1processOrder = $action({2 use: [$lock({ name: "process-order" })],3 handler: async ({ body }) => { ... },4});
#Options
| Option | Type | Required | Description |
|---|---|---|---|
name |
string | ((...args: any[]) => string) |
Yes | Lock key name |
wait |
boolean |
No | Whether to wait for the lock to become available. |
maxDuration |
DurationLike |
No | Maximum duration the lock can be held before automatic expiration. |