Skip to content

Commit 5b705cd

Browse files
aleclarsonjasnell
authored andcommitted
fs: add 'close' event to FSWatcher
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>
1 parent 27e6fd3 commit 5b705cd

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/api/fs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ added: v0.5.8
329329

330330
Emitted when an error occurs while watching the file.
331331

332+
### Event: 'close'
333+
<!-- YAML
334+
added: REPLACEME
335+
-->
336+
337+
Emitted when the watcher stops watching for changes.
338+
332339
### watcher.close()
333340
<!-- YAML
334341
added: v0.5.8

lib/fs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,13 @@ FSWatcher.prototype.close = function() {
13871387
return;
13881388
}
13891389
this._handle.close();
1390+
process.nextTick(emitCloseNT, this);
13901391
};
13911392

1393+
function emitCloseNT(self) {
1394+
self.emit('close');
1395+
}
1396+
13921397
fs.watch = function(filename, options, listener) {
13931398
if (typeof options === 'function') {
13941399
listener = options;

test/parallel/test-fs-watch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ for (const testCase of cases) {
5454
}
5555
assert.fail(err);
5656
});
57+
watcher.on('close', common.mustCall());
5758
watcher.on('change', common.mustCall(function(eventType, argFilename) {
5859
if (interval) {
5960
clearInterval(interval);

0 commit comments

Comments
 (0)