1 var wrappy = require('wrappy')
2 var reqs = Object.create(null)
3 var once = require('once')
5 module.exports = wrappy(inflight)
7 function inflight (key, cb) {
17 function makeres (key) {
18 return once(function RES () {
21 var args = slice(arguments)
23 // XXX It's somewhat ambiguous whether a new callback added in this
24 // pass should be queued for later execution if something in the
25 // list of callbacks throws, or if it should just be discarded.
26 // However, it's such an edge case that it hardly matters, and either
27 // choice is likely as surprising as the other.
28 // As it happens, we do go ahead and schedule it for later execution.
30 for (var i = 0; i < len; i++) {
31 cbs[i].apply(null, args)
34 if (cbs.length > len) {
35 // added more in the interim.
36 // de-zalgo, just in case, but don't call again.
38 process.nextTick(function () {
48 function slice (args) {
49 var length = args.length
52 for (var i = 0; i < length; i++) array[i] = args[i]