From 760bd984d863b8acbea049b77d9308d21cc3e822 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 15 May 2018 17:20:43 -0400 Subject: [PATCH] only close watcher when it's actually ready --- lib/pipeline/watch.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pipeline/watch.js b/lib/pipeline/watch.js index 910bb382..a2746716 100644 --- a/lib/pipeline/watch.js +++ b/lib/pipeline/watch.js @@ -41,8 +41,9 @@ class Watch { stop() { this.fileWatchers.forEach(fileWatcher => { - fileWatcher.close(); - fileWatcher = null; + if (fileWatcher.shouldClose) return; + if (fileWatcher.isReady) fileWatcher.close(); + fileWatcher.shouldClose = true; }); this.fileWatchers = []; } @@ -125,7 +126,11 @@ class Watch { .on('add', path => changeCallback('add', path)) .on('change', path => changeCallback('change', path)) .on('unlink', path => changeCallback('remove', path)) - .on('ready', doneCallback); + .once('ready', () => { + configWatcher.isReady = true; + if (configWatcher.shouldClose) configWatcher.close(); + doneCallback(); + }); } }