terminator.js 533B

123456789101112131415161718192021222324252627282930
  1. var abort = require('./abort.js')
  2. , async = require('./async.js')
  3. ;
  4. // API
  5. module.exports = terminator;
  6. /**
  7. * Terminates jobs in the attached state context
  8. *
  9. * @this AsyncKitState#
  10. * @param {function} callback - final callback to invoke after termination
  11. */
  12. function terminator(callback)
  13. {
  14. if (!Object.keys(this.jobs).length)
  15. {
  16. return;
  17. }
  18. // fast forward iteration index
  19. this.index = this.size;
  20. // abort jobs
  21. abort(this);
  22. // send back results we have so far
  23. async(callback)(null, this.results);
  24. }