# 八.AsyncSeriesBailHook

  • 只要有一个返回了不为 undefiend 的值就直接结束

# 1.使用方式

let { AsyncSeriesBailHook } = require("tapable")
class Lesson {
  constructor() {
    this.index = 0
    this.hooks = { arch: new AsyncSeriesBailHook(["name"]) }
  }
  tap() {
    this.hooks.arch.tapAsync("node", (name, cb) => {
      setTimeout(() => {
        console.log("node", name)
        cb()
      }, 1000)
    })
    this.hooks.arch.tapAsync("react", (name, cb) => {
      setTimeout(() => {
        console.log("react", name)
        cb()
      }, 1000)
    })
  }
  statr() {
    this.hooks.arch.callAsync("123", function () {
      console.log("end")
    })
  }
}
let l = new Lesson()
l.tap() //注册这两个事件
l.statr() //启动钩子
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

运行得到:

node 123
react 123
end
1
2
3