1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const asyncLib = require("neo-async");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | class MultiWatching {
|
21 | |
22 |
|
23 |
|
24 |
|
25 | constructor(watchings, compiler) {
|
26 | this.watchings = watchings;
|
27 | this.compiler = compiler;
|
28 | }
|
29 |
|
30 | invalidate(callback) {
|
31 | if (callback) {
|
32 | asyncLib.each(
|
33 | this.watchings,
|
34 | (watching, callback) => watching.invalidate(callback),
|
35 | callback
|
36 | );
|
37 | } else {
|
38 | for (const watching of this.watchings) {
|
39 | watching.invalidate();
|
40 | }
|
41 | }
|
42 | }
|
43 |
|
44 | suspend() {
|
45 | for (const watching of this.watchings) {
|
46 | watching.suspend();
|
47 | }
|
48 | }
|
49 |
|
50 | resume() {
|
51 | for (const watching of this.watchings) {
|
52 | watching.resume();
|
53 | }
|
54 | }
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 | close(callback) {
|
61 | asyncLib.forEach(
|
62 | this.watchings,
|
63 | (watching, finishedCallback) => {
|
64 | watching.close(finishedCallback);
|
65 | },
|
66 | err => {
|
67 | this.compiler.hooks.watchClose.call();
|
68 | if (typeof callback === "function") {
|
69 | this.compiler.running = false;
|
70 | callback(err);
|
71 | }
|
72 | }
|
73 | );
|
74 | }
|
75 | }
|
76 |
|
77 | module.exports = MultiWatching;
|