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.

AsyncSeriesBailHook.js 947B

12345678910111213141516171819202122232425262728293031323334353637
  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. class AsyncSeriesBailHook extends Hook {
  23. compile(options) {
  24. factory.setup(this, options);
  25. return factory.create(options);
  26. }
  27. }
  28. Object.defineProperties(AsyncSeriesBailHook.prototype, {
  29. _call: { value: undefined, configurable: true, writable: true }
  30. });
  31. module.exports = AsyncSeriesBailHook;