-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Node.js has long had a pattern of attaching a ref() and unref() method to various i/o objects that are bound to the event loop. Calling thing.unref() makes it so the thing does not keep the event loop alive.
For instance,
const i = setInterval(() => {}, 1000);
i.unref();While this has worked effectively for Node.js specific APIs, it's rather cumbersome with web platform standard APIs. I'd like to propose a change: Introduce new process.unref(thing) and process.ref(thing) API that would accept multiple different kinds of ref'able types.
const i = setInterval(() => {}, 1000);
process.unref(i);
// etc
A number of API objects that currently have .ref()/.unref() methods:
dgram.Socketnet.Socketnet.Serverchild_process.ChildProcesschild_process.ControlStatWatcherFSWatcherMessagePortTimeoutIntervalWorkerHttp2SessionBroadcastChannel
The idea would be to mark the existing object-specific ref() and unref() methods as legacy and depend on the process.ref()/process.unref() as the supported mechanism moving forward.
/cc @mcollina