Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: add 'close' event to FSWatcher #19900

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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