New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPC helper #900
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Proposal
Returning (with
return
orbreak
) from either the current process or the subprocess' loop automatically stops listening to the IPC channel.The parent loop waits for the
subprocess
to resolve. Also, it throws if thesubprocess
promise is rejected.Rationale
The above provides with a simpler syntax for IPC, using async iterables instead of events.
It also enforces best practices:
Disconnection
Ensures the
message
event handler is cleaned up to prevent processes hanging, and allows graceful exits.Otherwise, by default, the subprocess hangs until calling
.disconnect()
, which users might forget. Many might callprocess.exit()
in the subprocess, but that's a forceful exit which might interrupt ongoing logic.Error handling
Proper error handling. Errors in
message
handlers are correctly handled and propagated.Otherwise, by default, an exception in the
message
handler in the subprocess would result in an uncaught exception.Subprocess completion/error
Ensures the
subprocess
promise is awaited and its errors are propagated.Usually, if IPC is used, it tends to be during the whole lifetime of the subprocess. I.e. the
ipc
andsubprocess
promises overlap and can be combined.subprocess
does not need to be awaited ifsubprocess.ipc
is.What do you think?
Edit: some implementation notes:
on(subprocess, 'message')
under-the-hood.process.send()
andsubprocess.send()
to send messages. We keep those as is.iterable.return()
anditerable.throw()
should return a promise that waits for the subprocess to complete.for await
processes serially. However, users can achieve parallelism by calling async functions withoutawait
, although it would make error handling harder (although not impossible).The text was updated successfully, but these errors were encountered: