All Projects → iarna → promise-inflight

iarna / promise-inflight

Licence: ISC license
One promise for multiple requests in flight to avoid async duplication

Programming Languages

javascript
184084 projects - #8 most used programming language

promise-inflight

One promise for multiple requests in flight to avoid async duplication

USAGE

const inflight = require('promise-inflight')

// some request that does some stuff
function req(key) {
  // key is any random string.  like a url or filename or whatever.
  return inflight(key, () => {
    // this is where you'd fetch the url or whatever
    return Promise.delay(100)
  })
}

// only assigns a single setTimeout
// when it dings, all thens get called with the same result.  (There's only
// one underlying promise.)
req('foo').then()
req('foo').then()
req('foo').then()
req('foo').then()

SEE ALSO

  • inflight - For the callback based function on which this is based.

STILL NEEDS

Tests!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].