"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/asynckit/parallel.js" (8 Mar 2017, 1017 Bytes) of package /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 iterate    = require('./lib/iterate.js')
    2   , initState  = require('./lib/state.js')
    3   , terminator = require('./lib/terminator.js')
    4   ;
    5 
    6 // Public API
    7 module.exports = parallel;
    8 
    9 /**
   10  * Runs iterator over provided array elements in parallel
   11  *
   12  * @param   {array|object} list - array or object (named list) to iterate over
   13  * @param   {function} iterator - iterator to run
   14  * @param   {function} callback - invoked when all elements processed
   15  * @returns {function} - jobs terminator
   16  */
   17 function parallel(list, iterator, callback)
   18 {
   19   var state = initState(list);
   20 
   21   while (state.index < (state['keyedList'] || list).length)
   22   {
   23     iterate(list, iterator, state, function(error, result)
   24     {
   25       if (error)
   26       {
   27         callback(error, result);
   28         return;
   29       }
   30 
   31       // looks like it's the last one
   32       if (Object.keys(state.jobs).length === 0)
   33       {
   34         callback(null, state.results);
   35         return;
   36       }
   37     });
   38 
   39     state.index++;
   40   }
   41 
   42   return terminator.bind(state, callback);
   43 }