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
A very common IPC pattern is to retrieve a message, but only when it matches a specific shape. For example, if messages have a type field, only events of a specific type.
This is currently easy to do with subprocess.getEachMessage().
However, it is currently not simple to do the same with subprocess.getOneMessage(), i.e. when retrieving only one message this way.
Using a while loop is slightly cumbersome. But more importantly, if multiple messages are received at the same time (more precisely, if the message event if emitted multiple times in a single tick), then some messages will be lost and never received.
Background
A very common IPC pattern is to retrieve a message, but only when it matches a specific shape. For example, if messages have a
type
field, only events of a specific type.This is currently easy to do with
subprocess.getEachMessage()
.When async iterator helpers will be available in Node, the following functional alternative will be available too:
Problem
However, it is currently not simple to do the same with
subprocess.getOneMessage()
, i.e. when retrieving only one message this way.Using a
while
loop is slightly cumbersome. But more importantly, if multiple messages are received at the same time (more precisely, if themessage
event if emitted multiple times in a single tick), then some messages will be lost and never received.Solution
Adding a
filter
option tosubprocess.getOneMessage()
.The text was updated successfully, but these errors were encountered: