AsyncSeriesBailHook.js 886 B

1234567891011121314151617181920212223242526272829303132333435
  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, onDone }) {
  10. return this.callTapsSeries({
  11. onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
  12. onResult: (i, result, next) => `if(${result} !== undefined) {\n${onResult(result)};\n} else {\n${next()}}\n`,
  13. onDone
  14. });
  15. }
  16. }
  17. const factory = new AsyncSeriesBailHookCodeFactory();
  18. class AsyncSeriesBailHook extends Hook {
  19. constructor(args) {
  20. super(args);
  21. this.call = this._call = undefined;
  22. }
  23. compile(options) {
  24. factory.setup(this, options);
  25. return factory.create(options);
  26. }
  27. }
  28. module.exports = AsyncSeriesBailHook;