You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Migrating from object.ref()/object.unref() to process.ref()/process.unref() #53266
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,
consti=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.Socket
net.Socket
net.Server
child_process.ChildProcess
child_process.Control
StatWatcher
FSWatcher
MessagePort
Timeout
Interval
Worker
Http2Session
BroadcastChannel
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.
However we are never going to be able to remove the previous methods either (unfortunately), as they will break everybody.
Yeah, I know. My plan would be to keep those existing methods in place but change them to use the new mechanism under the covers. The public APIs would then be marked as legacy with a note to use the new process.(un)ref API.
Reacted by Yagiz Nizipli, Moshe Atlow and ExE Boss
Activity
benjamingr commentedon Jun 3, 2024
+1 this makes sense to do from the outside
mcollina commentedon Jun 4, 2024
+1 for me.
However we are never going to be able to remove the previous methods either (unfortunately), as they will break everybody.
anonrig commentedon Jun 6, 2024
+1
jasnell commentedon Jun 12, 2024
Ok, given the thumbs up on it, I'll start working this up
jasnell commentedon Jun 12, 2024
@mcollina :
Yeah, I know. My plan would be to keep those existing methods in place but change them to use the new mechanism under the covers. The public APIs would then be marked as legacy with a note to use the new
process.(un)refAPI.process: add process.ref() and process.unref() methods
process: add process.ref() and process.unref() methods
process: add process.ref() and process.unref() methods