2.0.0 • Published 6 years ago

max-in-flight v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Max In Flight

Limits max. async running operations.

current version travis.ci codecov Greenkeeper badge license

Install

npm install max-in-flight

Motivation:

I needed to call great amount of requests to http endpoint from different places of my server side app (graphql bridge with huge query running) and I needed to be sure that only XX requests will be in flight otherwise the server will go down.

There are other solutions when you have existing array of async functions to call and you need to limit their processing (starting).

This was not the case, I needed kind of FIFO queue for such calls, because the requests were initiated in multiple places of an app.

How to use it:

import maxInFlight from 'maxInFlight';
// limit number of max. concurrent async operation
const defer = maxInFlight(3).deferCall;
async function() {
  const result = await defer(
    fetch,
    'http://some.com', ... any other args for fetch ...);
}

// alternatively you can use it to defer fn and use this defered fn then
const deferFetch = maxInFlight(3).deferFn(fetch);
const result = await deferFetch('http://some.com', ...);

Error is propagated to the defer so operation may fail and will not take down other operations in flight or any submitted in the future.

License - MIT