提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.5 KiB

  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const asyncLib = require("neo-async");
  7. /** @typedef {import("./MultiCompiler")} MultiCompiler */
  8. /** @typedef {import("./Watching")} Watching */
  9. /** @typedef {import("./webpack").ErrorCallback} ErrorCallback */
  10. class MultiWatching {
  11. /**
  12. * @param {Watching[]} watchings child compilers' watchers
  13. * @param {MultiCompiler} compiler the compiler
  14. */
  15. constructor(watchings, compiler) {
  16. this.watchings = watchings;
  17. this.compiler = compiler;
  18. }
  19. /**
  20. * @param {ErrorCallback=} callback signals when the build has completed again
  21. * @returns {void}
  22. */
  23. invalidate(callback) {
  24. if (callback) {
  25. asyncLib.each(
  26. this.watchings,
  27. (watching, callback) => watching.invalidate(callback),
  28. (err) => {
  29. callback(err);
  30. }
  31. );
  32. } else {
  33. for (const watching of this.watchings) {
  34. watching.invalidate();
  35. }
  36. }
  37. }
  38. suspend() {
  39. for (const watching of this.watchings) {
  40. watching.suspend();
  41. }
  42. }
  43. resume() {
  44. for (const watching of this.watchings) {
  45. watching.resume();
  46. }
  47. }
  48. /**
  49. * @param {ErrorCallback} callback signals when the watcher is closed
  50. * @returns {void}
  51. */
  52. close(callback) {
  53. asyncLib.each(
  54. this.watchings,
  55. (watching, finishedCallback) => {
  56. watching.close(finishedCallback);
  57. },
  58. (err) => {
  59. this.compiler.hooks.watchClose.call();
  60. if (typeof callback === "function") {
  61. this.compiler.running = false;
  62. callback(err);
  63. }
  64. }
  65. );
  66. }
  67. }
  68. module.exports = MultiWatching;