Skip to content

Commit

Permalink
fs: add 'close' event to FSWatcher
Browse files Browse the repository at this point in the history
PR-URL: #19900
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
aleclarson authored and jasnell committed Apr 16, 2018
1 parent 27e6fd3 commit 5b705cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ added: v0.5.8

Emitted when an error occurs while watching the file.

### Event: 'close'
<!-- YAML
added: REPLACEME
-->

Emitted when the watcher stops watching for changes.

### watcher.close()
<!-- YAML
added: v0.5.8
Expand Down
5 changes: 5 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,13 @@ FSWatcher.prototype.close = function() {
return;
}
this._handle.close();
process.nextTick(emitCloseNT, this);
};

function emitCloseNT(self) {
self.emit('close');
}

fs.watch = function(filename, options, listener) {
if (typeof options === 'function') {
listener = options;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ for (const testCase of cases) {
}
assert.fail(err);
});
watcher.on('close', common.mustCall());
watcher.on('change', common.mustCall(function(eventType, argFilename) {
if (interval) {
clearInterval(interval);
Expand Down

0 comments on commit 5b705cd

Please sign in to comment.