-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
A test would be good, yes. |
Docs are needed as well. |
Why do you need a |
@mcollina To keep the function watch(root) {
return fs.watch(root, (evt, file) => {
// ...
}).on('close', () => {
// ...
})
} Currently, I'm monkey-patching the function watch(root) {
let watcher = fs.watch(root, (evt, file) => {
// ...
})
let {close} = watcher
watcher.close = function() {
close.call(watcher)
// ...
}
return watcher
} |
@aleclarson definitely better. Can you add a unit test? |
Added a test and docs. Note the |
@aleclarson the |
test/parallel/test-fs-watch.js
Outdated
@@ -54,6 +54,10 @@ for (const testCase of cases) { | |||
} | |||
assert.fail(err); | |||
}); | |||
let closeCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the closeCount
, and just write watcher.on('close', common.mustCall());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that protect against multiple calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Good to go 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/fs.js
Outdated
@@ -1387,6 +1387,7 @@ FSWatcher.prototype.close = function() { | |||
return; | |||
} | |||
this._handle.close(); | |||
this.emit('close'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you wrap this in a process.nextTick()
? Zalgo and all that.
Ping @aleclarson |
Now wrapped with |
Landed in 5cc948b. |
PR-URL: #19900 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #19900 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: nodejs#19900 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Should
process.nextTick
wrap this? Are tests necessary here?