UNPKG

limiter

Version:

A generic rate limiter for the web and node.js. Useful for API clients, web crawling, or other tasks that need to be throttled

15 lines 488 B
/** Serialize waiting requests so a backlog needs only one active timer. */ export class RequestQueue { tail; run(request) { const result = this.tail ? this.tail.then(request) : request(); const tail = result.then(() => undefined, () => undefined); this.tail = tail; void tail.then(() => { if (this.tail === tail) this.tail = undefined; }); return result; } } //# sourceMappingURL=RequestQueue.js.map