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