fs: add 'close' event to FSWatcher#19900
fs: add 'close' event to FSWatcher#19900aleclarson wants to merge 3 commits intonodejs:masterfrom aleclarson:patch-1
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
There was a problem hiding this comment.
You can drop the closeCount, and just write watcher.on('close', common.mustCall());
There was a problem hiding this comment.
Does that protect against multiple calls?
|
Good to go 👍 |
lib/fs.js
Outdated
There was a problem hiding this comment.
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 <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>
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>
PR-URL: nodejs#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>
Should
process.nextTickwrap this? Are tests necessary here?