As @LiarPrincess pointed out in the pitch thread, waiting for exit and reading outputs (stdout or stderr) are inherently coupled, due to finite buffers that may be (and often are) involved. The API currently exposes many deadlock scenarios by having them be separate.
It's important to be able to read from stdout & stderr as a logically single stream. Otherwise, you might be awaiting on stdout while the subprocess has communicated via stderr, or vice versa, and deadlock.
It's also important to not await on subprocesses termination until stdout & stderr are already closed. Perhaps wait
shouldn't be available on Subprocess
, but rather something you get access to by closing stdout & stderr? e.g. closing them (both) returns a token object which provides the wait
method, along with whatever other handful of functions still make sense at that time.
You can naturally read to EOF on them (stdout & stderr), or force them closed, but either way until they're closed it's not safe to wait for subprocess termination.