decorio
Version:
First-class ECMAScript decorators for caching, binding, and concurrency patterns
18 lines (17 loc) • 857 B
TypeScript
/**
* 🎯 Decorator that ensures only a single in-flight invocation per argument list.
* Subsequent calls with the same arguments return the same Promise until it settles.
*
* Usage:
* ```typescript
* class Example {
* @singleflight async fetchData(id: string): Promise<Data> { ... }
* }
*
* const e = new Example();
* const p1 = e.fetchData('foo');
* const p2 = e.fetchData('foo'); // returns same Promise as p1
* ```
*/
export declare function singleflight<A extends Array<unknown>, R extends Promise<unknown>>(value: unknown, context: ClassMethodDecoratorContext<object, (...args: A) => R>): (...args: A) => R;
export declare function singleflight<A extends Array<unknown>, R extends Promise<unknown>>(value: unknown, context: ClassFieldDecoratorContext<object, (...args: A) => R>): (originalFn: (...args: A) => R) => (...args: A) => R;