settleSeries.js 677 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var initial = require('array-initial');
  3. var last = require('array-last');
  4. var asyncSettle = require('async-settle');
  5. var nowAndLater = require('now-and-later');
  6. var helpers = require('./helpers');
  7. function iterator(fn, key, cb) {
  8. return asyncSettle(fn, cb);
  9. }
  10. function buildSettleSeries() {
  11. var args = helpers.verifyArguments(arguments);
  12. var extensions = helpers.getExtensions(last(args));
  13. if (extensions) {
  14. args = initial(args);
  15. }
  16. function settleSeries(done) {
  17. var onSettled = helpers.onSettled(done);
  18. nowAndLater.mapSeries(args, iterator, extensions, onSettled);
  19. }
  20. return settleSeries;
  21. }
  22. module.exports = buildSettleSeries;