You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
533 B

  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. }