MultiWatching.js 886 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. class MultiWatching {
  8. constructor(watchings, compiler) {
  9. this.watchings = watchings;
  10. this.compiler = compiler;
  11. }
  12. invalidate() {
  13. for (const watching of this.watchings) {
  14. watching.invalidate();
  15. }
  16. }
  17. suspend() {
  18. for (const watching of this.watchings) {
  19. watching.suspend();
  20. }
  21. }
  22. resume() {
  23. for (const watching of this.watchings) {
  24. watching.resume();
  25. }
  26. }
  27. close(callback) {
  28. asyncLib.forEach(
  29. this.watchings,
  30. (watching, finishedCallback) => {
  31. watching.close(finishedCallback);
  32. },
  33. err => {
  34. this.compiler.hooks.watchClose.call();
  35. if (typeof callback === "function") {
  36. this.compiler.running = false;
  37. callback(err);
  38. }
  39. }
  40. );
  41. }
  42. }
  43. module.exports = MultiWatching;