-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
fs: add .ref() and .unref() methods to the StatWatcher and FSWatcher #33134
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,29 @@ added: v0.5.8 | |
| Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the | ||
| `fs.FSWatcher` object is no longer usable. | ||
|
|
||
| ### `watcher.ref()` | ||
| <!-- YAML | ||
| added: REPLACEME | ||
| --> | ||
|
|
||
| When called, requests that the Node.js event loop *not* exit so long as the | ||
| `FSWatcher` is active. Calling `watcher.ref()` multiple times will have | ||
| no effect. | ||
|
|
||
| By default, all `FSWatcher` objects are "ref'ed", making it normally | ||
| unnecessary to call `watcher.ref()` unless `watcher.unref()` had been | ||
| called previously. | ||
|
|
||
| ### `watcher.unref()` | ||
| <!-- YAML | ||
| added: REPLACEME | ||
| --> | ||
| When called, the active `FSWatcher` object will not require the Node.js | ||
| event loop to remain active. If there is no other activity keeping the | ||
| event loop running, the process may exit before the `FSWatcher` object's | ||
| callback is invoked. Calling `watcher.unref()` multiple times will have | ||
| no effect. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods should probably also be documented for the return value of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, there are other methods like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
|
||
| ## Class: `fs.ReadStream` | ||
| <!-- YAML | ||
| added: v0.1.93 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| if (common.isIBMi) | ||
| common.skip('IBMi does not support `fs.watch()`'); | ||
|
|
||
| const fs = require('fs'); | ||
| const assert = require('assert'); | ||
|
|
||
| let refCount = 0; | ||
|
|
||
| const watcher = fs.watch(__filename, common.mustNotCall()); | ||
|
|
||
| function unref() { | ||
| watcher.unref(); | ||
| refCount--; | ||
| assert.strictEqual(refCount, -1); | ||
| } | ||
|
|
||
| function ref() { | ||
| watcher.ref(); | ||
| refCount++; | ||
| assert.strictEqual(refCount, 0); | ||
| } | ||
|
|
||
| unref(); | ||
|
|
||
| setTimeout( | ||
| common.mustCall(() => { | ||
| ref(); | ||
| unref(); | ||
| }), | ||
| common.platformTimeout(100) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| const fs = require('fs'); | ||
| const assert = require('assert'); | ||
|
|
||
| let refCount = 0; | ||
|
|
||
| const watcher = fs.watchFile(__filename, common.mustNotCall()); | ||
|
|
||
| function unref() { | ||
| watcher.unref(); | ||
| refCount--; | ||
|
rickyes marked this conversation as resolved.
Outdated
|
||
| assert.strictEqual(refCount, -1); | ||
| } | ||
|
|
||
| function ref() { | ||
| watcher.ref(); | ||
| refCount++; | ||
| assert.strictEqual(refCount, 0); | ||
| } | ||
|
|
||
| unref(); | ||
|
|
||
| setTimeout( | ||
| common.mustCall(() => { | ||
| ref(); | ||
| unref(); | ||
| watcher.unref(); | ||
| watcher.ref(); | ||
| watcher.ref(); | ||
| watcher.unref(); | ||
| }), | ||
| common.platformTimeout(100) | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.