Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,10 @@ function watch(filename, options, listener) {
if (!watchers)
watchers = require('internal/fs/watchers');
const watcher = new watchers.FSWatcher();
watcher.start(filename,
options.persistent,
options.recursive,
options.encoding);
watcher._start(filename,
options.persistent,
options.recursive,
options.encoding);

if (listener) {
watcher.addListener('change', listener);
Expand Down
14 changes: 6 additions & 8 deletions lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,16 @@ function FSWatcher() {
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
Object.setPrototypeOf(FSWatcher, EventEmitter);


// FIXME(joyeecheung): this method is not documented.
// At the moment if filename is undefined, we
// 1. Throw an Error if it's the first time .start() is called
// 2. Return silently if .start() has already been called
// 1. Throw an Error if it's the first time ._start() is called
// 2. Return silently if ._start() has already been called
// on a valid filename and the wrap has been initialized
// 3. Return silently if the watcher has already been closed
// This method is a noop if the watcher has already been started.
FSWatcher.prototype.start = function(filename,
persistent,
recursive,
encoding) {
FSWatcher.prototype._start = function(filename,
persistent,
recursive,
encoding) {
if (this._handle === null) { // closed
return;
}
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ for (const testCase of cases) {
watcher.on('close', common.mustCall(() => {
watcher.close(); // Closing a closed watcher should be a noop
// Starting a closed watcher should be a noop
watcher.start();
watcher._start();
}));
watcher.on('change', common.mustCall(function(eventType, argFilename) {
if (interval) {
Expand All @@ -72,15 +72,15 @@ for (const testCase of cases) {
assert.strictEqual(argFilename, testCase.fileName);

// Starting a started watcher should be a noop
watcher.start();
watcher.start(pathToWatch);
watcher._start();
watcher._start(pathToWatch);

watcher.close();

// We document that watchers cannot be used anymore when it's closed,
// here we turn the methods into noops instead of throwing
watcher.close(); // Closing a closed watcher should be a noop
watcher.start(); // Starting a closed watcher should be a noop
watcher._start(); // Starting a closed watcher should be a noop
}));

// Long content so it's actually flushed. toUpperCase so there's real change.
Expand Down