"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/node_modules/inflight/inflight.js" (8 Mar 2017, 897 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var wrappy = require('wrappy')
    2 var reqs = Object.create(null)
    3 var once = require('once')
    4 
    5 module.exports = wrappy(inflight)
    6 
    7 function inflight (key, cb) {
    8   if (reqs[key]) {
    9     reqs[key].push(cb)
   10     return null
   11   } else {
   12     reqs[key] = [cb]
   13     return makeres(key)
   14   }
   15 }
   16 
   17 function makeres (key) {
   18   return once(function RES () {
   19     var cbs = reqs[key]
   20     var len = cbs.length
   21     var args = slice(arguments)
   22     for (var i = 0; i < len; i++) {
   23       cbs[i].apply(null, args)
   24     }
   25     if (cbs.length > len) {
   26       // added more in the interim.
   27       // de-zalgo, just in case, but don't call again.
   28       cbs.splice(0, len)
   29       process.nextTick(function () {
   30         RES.apply(null, args)
   31       })
   32     } else {
   33       delete reqs[key]
   34     }
   35   })
   36 }
   37 
   38 function slice (args) {
   39   var length = args.length
   40   var array = []
   41 
   42   for (var i = 0; i < length; i++) array[i] = args[i]
   43   return array
   44 }