Sha256: 2e23a7bb38b8fc1538f018ef2bedd6ee2bcc38c57f063fd4395baa46ff2333be

Contents?: true

Size: 897 Bytes

Versions: 227

Compression:

Stored size: 897 Bytes

Contents

var wrappy = require('wrappy')
var reqs = Object.create(null)
var once = require('once')

module.exports = wrappy(inflight)

function inflight (key, cb) {
  if (reqs[key]) {
    reqs[key].push(cb)
    return null
  } else {
    reqs[key] = [cb]
    return makeres(key)
  }
}

function makeres (key) {
  return once(function RES () {
    var cbs = reqs[key]
    var len = cbs.length
    var args = slice(arguments)
    for (var i = 0; i < len; i++) {
      cbs[i].apply(null, args)
    }
    if (cbs.length > len) {
      // added more in the interim.
      // de-zalgo, just in case, but don't call again.
      cbs.splice(0, len)
      process.nextTick(function () {
        RES.apply(null, args)
      })
    } else {
      delete reqs[key]
    }
  })
}

function slice (args) {
  var length = args.length
  var array = []

  for (var i = 0; i < length; i++) array[i] = args[i]
  return array
}

Version data entries

227 entries across 137 versions & 14 rubygems

Version Path
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
opal-0.10.2 stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
minimum_viable_product-0.0.11 test/dummy/node_modules/inflight/inflight.js
brwy_rails-0.0.6 test/dummy/node_modules/inflight/inflight.js
brwy_rails-0.0.6 test/dummy/node_modules/fsevents/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
brwy_rails-0.0.5 test/dummy/node_modules/fsevents/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js
brwy_rails-0.0.5 test/dummy/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/glob/node_modules/inflight/inflight.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js