@soncodi/reqqueue
v1.0.5
Published
Sequential request queue for Node.js and browsers.
Downloads
3
Maintainers
Readme
ReqQueue
Sequential request queue for Node.js and browsers. No dependencies.
- Requests are executed in the order in which they were queued
- Execution of requests is sequential (not interleaved)
- Supports requests with both sync and async results
Installation
npm install @soncodi/reqqueue --save
Usage (TypeScript)
import { ReqQueue } from '@soncodi/reqqueue';
const q = new ReqQueue(false);
const request = async () => {
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000));
return Math.random();
};
const [a, b, c] = await Promise.all([
q.add(request);
q.add(request);
q.add(request);
]);
Methods
add<T>(fn: (...args: any[]) => T|Promise<T>): Promise<T>
Adds a request to the request queue to be executed.