1.0.5 • Published 4 years ago

@soncodi/reqqueue v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

ReqQueue

Build Status Coverage Status Dependency Status npm version

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.