socket.unref()


默认情况下,绑定套接字会导致 Node.js 进程在套接字打开的情况下无法退出。可以使用 socket.unref() 方法将套接字排除在保持 Node.js 进程活跃的引用计数之外,即使套接字仍在监听,也允许进程退出。

【By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The socket.unref() method can be used to exclude the socket from the reference counting that keeps the Node.js process active, allowing the process to exit even if the socket is still listening.】

多次调用 socket.unref() 不会产生额外效果。

【Calling socket.unref() multiple times will have no additional effect.】

socket.unref() 方法返回对套接字的引用,因此可以进行链式调用。

【The socket.unref() method returns a reference to the socket so calls can be chained.】