Skip to content

Unref FSWatcher #33096

@szmarczak

Description

@szmarczak

Is your feature request related to a problem? Please describe.

Currently, when you do fs.watchFile(...) the process will run forever.

Describe the solution you'd like

A possibility to watcher.unref() would be great.

Describe alternatives you've considered

const watchFile = (path, callback, onError) => {
	let previousTime = null;

	const interval = setInterval(async () => {
		try {
			const {mtimeMs} = await stat(path);

			if (previousTime !== null && mtimeMs !== previousTime) {
				callback(mtimeMs, previousTime);
			}

			previousTime = mtimeMs;
		} catch (error) {
			clearInterval(interval);

			// The error part is off the Node.js API
			onError(error);
		}
	}, 1000 * 60).unref();
};

Edit: seems like the code above is completely unnecessary 🤦‍♂️

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions