-
Notifications
You must be signed in to change notification settings - Fork 0
/
09asyncserieswaterfallhook.js
44 lines (37 loc) · 1.1 KB
/
09asyncserieswaterfallhook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* @Date: 2022-02-24 15:20:55
* @LastEditors: jimouspeng
* @Description: AsyncSeriesWaterfallHook-串行执行,并且前一个插件的返回值,会作为后一个插件的参数
* @LastEditTime: 2022-02-24 15:28:05
* @FilePath: \tapable\09asyncserieswaterfallhook.js
*/
const { AsyncSeriesWaterfallHook } = require('tapable')
const hook = new AsyncSeriesWaterfallHook(['name'])
// 异步钩子注册方式: tapAsync, tapPromise(return a promise)
hook.tapPromise('a', (name) => {
return new Promise((resolve) => {
setTimeout(() => {
console.log(name, 'a---')
resolve('is')
}, 3000)
})
})
hook.tapPromise('b', (name) => {
return new Promise((resolve) => {
setTimeout(() => {
console.log(name, 'b----')
resolve('cool')
}, 2000)
})
})
hook.tapPromise('c', (name) => {
return new Promise((resolve) => {
setTimeout(() => {
console.log(name, 'c----')
resolve('jimous is cool')
}, 1000)
})
})
hook.promise('jimous').then((res) => {
console.log(res, '执行完毕')
})