1.0.1 • Published 2 years ago

@tuluffy/promise-pool v1.0.1

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

Promise Pool

Promise-Pool is a JavaScript library for Scheduling requests.

specifying the number of concurrent requests, and reducing the pressure on target services.

Installation

Using npm/yarn:

npm install @tuluffy/promise-pool --save

How to use

test example

const fn1 = () => new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve('fn1...');
	}, 1700);
});

const fn2 = () => new Promise((resolve, reject) => {
	setTimeout(() => {
		reject('reject fn2...');
	}, 1000);
});

const fn3 = () => new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve('fn3...');
	}, 800);
});

const fn4 = () => new Promise((resolve, reject) => {
	setTimeout(() => {
		reject('reject fn4...');
	}, 500);
});

use in project

import promisePool from '@tuluffy/promise-pool';

/* (Optional) Process response */
const callback = data => {
	console.log(data);
};

/* The number of transactions is limited to:2 */
const dispatch = PromisePool(2, callback);

const fn0 = () => new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve('fn0...');
	}, 600);
});

dispatch(fn0);
dispatch(fn1);
dispatch(fn2);
dispatch(fn3);
dispatch(fn4);

Change Log

1.0.1 (July 16, 2022)

  • adjustment readme;

Follow Up

Why should I make this tool?