alepha@docs:~/docs/reference/primitives$
cat $debounce.md1 min read
#$debounce
#Import
typescript
1import { $debounce } from "alepha/datetime";
#Overview
Coalescing window. Concurrent calls within this window share one execution. */ delay: DurationLike;
/**
- Key function to group calls. Calls with the same key are coalesced.
- Defaults to
JSON.stringify(args). */ key?: (...args: any[]) => string; }
/** Middleware that coalesces concurrent calls with the same key into a single handler execution.
All callers within the delay window receive the same result. No storage — once the handler finishes, the next call starts fresh. Process-local.
Use case: thundering herd protection — cache expires, 100 requests hit the same endpoint, debounce ensures one rebuild.
typescript
1class SearchController {2 search = $action({3 use: [$debounce({ delay: [200, "ms"], key: (req) => req.query.q })],4 handler: async ({ query }) => this.searchService.search(query.q),5 });6}
#Options
| Option | Type | Required | Description |
|---|---|---|---|
delay |
DurationLike |
Yes | Coalescing window |
key |
Object |
No | Key function to group calls |