AsyncSeriesBailHook.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Hook = require("./Hook");
  7. const HookCodeFactory = require("./HookCodeFactory");
  8. class AsyncSeriesBailHookCodeFactory extends HookCodeFactory {
  9. content({ onError, onResult, resultReturns, onDone }) {
  10. return this.callTapsSeries({
  11. onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
  12. onResult: (i, result, next) =>
  13. `if(${result} !== undefined) {\n${onResult(
  14. result
  15. )}\n} else {\n${next()}}\n`,
  16. resultReturns,
  17. onDone
  18. });
  19. }
  20. }
  21. const factory = new AsyncSeriesBailHookCodeFactory();
  22. const COMPILE = function(options) {
  23. factory.setup(this, options);
  24. return factory.create(options);
  25. };
  26. function AsyncSeriesBailHook(args = [], name = undefined) {
  27. const hook = new Hook(args, name);
  28. hook.constructor = AsyncSeriesBailHook;
  29. hook.compile = COMPILE;
  30. hook._call = undefined;
  31. hook.call = undefined;
  32. return hook;
  33. }
  34. AsyncSeriesBailHook.prototype = null;
  35. module.exports = AsyncSeriesBailHook;