when is MessagePort garbage collected, and when should I call .unref()?

86 Views Asked by At

In the past, I've seen that using a MessageChannel or MessagePort will prevent my process from exiting when it is done.

I see there's an .unref() method on MessagePort that can be called, but the docs aren't very clear on how best to use it.

Do I need to wait until all messages have been sent/received before calling .unref()? Will calling it prevent messages from being delivered? Or can I call it as soon as it's created? In addition, do I need to call .unref() on both ends of a MessageChannel, or just one of them?

0

There are 0 best solutions below