-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add .ref() and .unref() methods to watcher classes
PR-URL: #33134 Fixes: #33096 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
f33e866
commit 1dcf66c
Showing
7 changed files
with
183 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (common.isIBMi) | ||
common.skip('IBMi does not support `fs.watch()`'); | ||
|
||
const fs = require('fs'); | ||
|
||
const watcher = fs.watch(__filename, common.mustNotCall()); | ||
|
||
watcher.unref(); | ||
|
||
setTimeout( | ||
common.mustCall(() => { | ||
watcher.ref(); | ||
watcher.unref(); | ||
}), | ||
common.platformTimeout(100) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
|
||
const uncalledListener = common.mustNotCall(); | ||
const uncalledListener2 = common.mustNotCall(); | ||
const watcher = fs.watchFile(__filename, uncalledListener); | ||
|
||
watcher.unref(); | ||
watcher.unref(); | ||
watcher.ref(); | ||
watcher.unref(); | ||
watcher.ref(); | ||
watcher.ref(); | ||
watcher.unref(); | ||
|
||
fs.unwatchFile(__filename, uncalledListener); | ||
|
||
// Watch the file with two different listeners. | ||
fs.watchFile(__filename, uncalledListener); | ||
const watcher2 = fs.watchFile(__filename, uncalledListener2); | ||
|
||
setTimeout( | ||
common.mustCall(() => { | ||
fs.unwatchFile(__filename, common.mustNotCall()); | ||
assert.strictEqual(watcher2.listenerCount('change'), 2); | ||
fs.unwatchFile(__filename, uncalledListener); | ||
assert.strictEqual(watcher2.listenerCount('change'), 1); | ||
watcher2.unref(); | ||
}), | ||
common.platformTimeout(100) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters