Sha256: 5296e5c3581ad9dc1f04aedaf1132df9736c580a326970e3975856f73aebfaea

Contents?: true

Size: 1017 Bytes

Versions: 91

Compression:

Stored size: 1017 Bytes

Contents

var iterate    = require('./lib/iterate.js')
  , initState  = require('./lib/state.js')
  , terminator = require('./lib/terminator.js')
  ;

// Public API
module.exports = parallel;

/**
 * Runs iterator over provided array elements in parallel
 *
 * @param   {array|object} list - array or object (named list) to iterate over
 * @param   {function} iterator - iterator to run
 * @param   {function} callback - invoked when all elements processed
 * @returns {function} - jobs terminator
 */
function parallel(list, iterator, callback)
{
  var state = initState(list);

  while (state.index < (state['keyedList'] || list).length)
  {
    iterate(list, iterator, state, function(error, result)
    {
      if (error)
      {
        callback(error, result);
        return;
      }

      // looks like it's the last one
      if (Object.keys(state.jobs).length === 0)
      {
        callback(null, state.results);
        return;
      }
    });

    state.index++;
  }

  return terminator.bind(state, callback);
}

Version data entries

91 entries across 89 versions & 22 rubygems

Version Path
enju_library-0.3.8 spec/dummy/node_modules/asynckit/parallel.js
ilog-0.4.1 node_modules/asynckit/parallel.js
ilog-0.4.0 node_modules/asynckit/parallel.js
ilog-0.3.3 node_modules/asynckit/parallel.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/asynckit/parallel.js
jester-data-8.0.0 node_modules/asynckit/parallel.js
ezii-os-5.2.1 node_modules/asynckit/parallel.js
ezii-os-2.0.1 node_modules/asynckit/parallel.js
ezii-os-1.1.0 node_modules/asynckit/parallel.js
ezii-os-1.0.0 node_modules/asynckit/parallel.js
ezii-os-0.0.0.1.0 node_modules/asynckit/parallel.js
ezii-os-0.0.0.0.1 node_modules/asynckit/parallel.js
optimacms-0.4.3 spec/dummy/node_modules/asynckit/parallel.js
optimacms-0.4.2 spec/dummy/node_modules/asynckit/parallel.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/asynckit/parallel.js
lux_assets-0.2.11 ./node_modules/asynckit/parallel.js
lux_assets-0.2.9 ./node_modules/asynckit/parallel.js
lux_assets-0.2.4 ./node_modules/asynckit/parallel.js
lux_assets-0.2.2 ./node_modules/asynckit/parallel.js
lux_assets-0.2.1 ./node_modules/asynckit/parallel.js