Skip to content

Commit

Permalink
Only close the watcher after the ready event is emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed May 3, 2018
1 parent a176ded commit 6cc6218
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class Watcher {
});

this.watchedDirectories = new Map();

// Only close the watcher after the ready event is emitted
this.ready = false;
this.stopped = false;
this.watcher.once('ready', () => {
this.ready = true;
if (this.stopped) {
this.watcher.close();
}
});
}

/**
Expand Down Expand Up @@ -117,7 +127,10 @@ class Watcher {
* Stop watching all paths
*/
stop() {
this.watcher.close();
this.stopped = true;
if (this.ready) {
this.watcher.close();
}
}
}

Expand Down

0 comments on commit 6cc6218

Please sign in to comment.