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

19 lines 626 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestQueue = void 0; /** Serialize waiting requests so a backlog needs only one active timer. */ 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; } } exports.RequestQueue = RequestQueue; //# sourceMappingURL=RequestQueue.js.map