Skip to content

cafutor/request-pool

Repository files navigation

request-pool

install

npm install request-limit-pool@latest --save

useage

import RequestPool from 'request-limit-pool';

//set the maximum number of requests to 3. default is 3.
const requestPool = new RequestPool(3);

// the request method must return a promise instance.
const request = () => {
  return fetchUser().then((data) => {
    // processing data
  });
};

// then push the request to the queue and request-pool will excute it.
requestPool.push(request);
requestPool.push(request);
requestPool.push(request);
requestPool.push(request);

// when all requests are finished,the callback will be called.
const unsubscribe = requestPool.done(() => {
  // is done
  //...

  //unsubscribe if you want
  unsubscribe();
});

// you can subscribe multiple times.
requestPool.done(() => {
  // is done
});

Releases

No releases published

Packages

No packages published