All Projects → npm → inflight

npm / inflight

Licence: ISC license
Add callbacks to requests in flight to avoid async duplication

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to inflight

Cli
the package manager for JavaScript
Stars: ✭ 5,277 (+8276.19%)
Mutual labels:  npm-cli
Node Semver
The semver parser for node (the one npm uses)
Stars: ✭ 3,944 (+6160.32%)
Mutual labels:  npm-cli
run-script
Run a lifecycle script for a package (descendant of npm-lifecycle)
Stars: ✭ 29 (-53.97%)
Mutual labels:  npm-cli
lint
lint the npmcli way
Stars: ✭ 27 (-57.14%)
Mutual labels:  npm-cli
proggy
Progress bar updates at a distance
Stars: ✭ 12 (-80.95%)
Mutual labels:  npm-cli
pacote
npm fetcher
Stars: ✭ 179 (+184.13%)
Mutual labels:  npm-cli
parse-conflict-json
Parse a JSON string that has git merge conflicts, resolving if possible
Stars: ✭ 24 (-61.9%)
Mutual labels:  npm-cli
libnpmpublish
programmatically publish and unpublish npm packages
Stars: ✭ 44 (-30.16%)
Mutual labels:  npm-cli
config
Configuration management for https://github.com/npm/cli
Stars: ✭ 22 (-65.08%)
Mutual labels:  npm-cli
cacache
npm's content-addressable cache
Stars: ✭ 181 (+187.3%)
Mutual labels:  npm-cli
cmd-shim
The cmd-shim used in npm
Stars: ✭ 65 (+3.17%)
Mutual labels:  npm-cli
libnpmsearch
programmatic API for the shiny new npm search endpoint
Stars: ✭ 25 (-60.32%)
Mutual labels:  npm-cli
cross-post
Cross Post a blog to multiple websites
Stars: ✭ 66 (+4.76%)
Mutual labels:  npm-cli
git
a util for spawning git from npm CLI contexts
Stars: ✭ 48 (-23.81%)
Mutual labels:  npm-cli
fs-minipass
fs read and write streams based on minipass
Stars: ✭ 15 (-76.19%)
Mutual labels:  npm-cli
npm-registry-mock
mock the npm registry
Stars: ✭ 26 (-58.73%)
Mutual labels:  npm-cli
node-cli-boilerplate
🪓 Create node cli with this user friendly boilerplate
Stars: ✭ 17 (-73.02%)
Mutual labels:  npm-cli
npm-profile
Make changes to your npmjs.com profile via cli or library
Stars: ✭ 29 (-53.97%)
Mutual labels:  npm-cli

inflight

Add callbacks to requests in flight to avoid async duplication

USAGE

var inflight = require('inflight')

// some request that does some stuff
function req(key, callback) {
  // key is any random string.  like a url or filename or whatever.
  //
  // will return either a falsey value, indicating that the
  // request for this key is already in flight, or a new callback
  // which when called will call all callbacks passed to inflightk
  // with the same key
  callback = inflight(key, callback)

  // If we got a falsey value back, then there's already a req going
  if (!callback) return

  // this is where you'd fetch the url or whatever
  // callback is also once()-ified, so it can safely be assigned
  // to multiple events etc.  First call wins.
  setTimeout(function() {
    callback(null, key)
  }, 100)
}

// only assigns a single setTimeout
// when it dings, all cbs get called
req('foo', cb1)
req('foo', cb2)
req('foo', cb3)
req('foo', cb4)
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].