diff options
author | Alec Larson <aleclarson@users.noreply.github.com> | 2018-04-09 15:00:18 -0400 |
---|---|---|
committer | Luigi Pinca <luigipinca@gmail.com> | 2018-04-16 14:23:11 +0200 |
commit | 5cc948b77a1452cdd8b667978c3cc1188b433b1a (patch) | |
tree | 0e61539bf10c235f2c3d42f3d419f99910aea460 | |
parent | 809eb27bda6d1fb3f165d565ff4be83682938c9d (diff) | |
download | android-node-v8-5cc948b77a1452cdd8b667978c3cc1188b433b1a.tar.gz android-node-v8-5cc948b77a1452cdd8b667978c3cc1188b433b1a.tar.bz2 android-node-v8-5cc948b77a1452cdd8b667978c3cc1188b433b1a.zip |
fs: add 'close' event to FSWatcher
PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r-- | doc/api/fs.md | 7 | ||||
-rw-r--r-- | lib/fs.js | 5 | ||||
-rw-r--r-- | test/parallel/test-fs-watch.js | 1 |
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 @@ -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); |