summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/fs.md7
-rw-r--r--lib/fs.js5
-rw-r--r--test/parallel/test-fs-watch.js1
3 files changed, 13 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md
index 69138b6ac4..bf4261c15c 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -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
diff --git a/lib/fs.js b/lib/fs.js
index 6b80af3b63..6c8417030b 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -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;
diff --git a/test/parallel/test-fs-watch.js b/test/parallel/test-fs-watch.js
index 94a81799e5..ffa82e52c7 100644
--- a/test/parallel/test-fs-watch.js
+++ b/test/parallel/test-fs-watch.js
@@ -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);