title: typed-process withProcessWait_ and getExitCode race condition?
body: <pre><code>import System.Process.Typed
  import Control.Monad.STM
  import Control.Concurrent.STM.TVar
  
  processConf = setStderr byteStringOutput . setStdout byteStringOutput
  
  main :: IO ()
  main = do
    withProcessWait_ (processConf $ proc "sleep" ["1"])
            $ \p -&gt; do
              atomically (getStdout p) &gt;&gt;= print
              atomically (getStderr p) &gt;&gt;= print
              getExitCode p &gt;&gt;= print
    print "test"
  </code></pre>
  
  <p>The above code mostly returns <code>Nothing</code> for the exit code, while other times it'll return <code>Just ExitSuccess</code>, so seemingly random / race condition.</p>
  
  <p>Why might this occur?</p>
  
  <p>The function in question is: <a href="http://hackage.haskell.org/package/typed-process-0.2.6.0/docs/System-Process-Typed.html#v:withProcessWait_" rel="nofollow noreferrer">http://hackage.haskell.org/package/typed-process-0.2.6.0/docs/System-Process-Typed.html#v:withProcessWait_</a></p>
  
  <pre><code>withProcessWait_ :: MonadUnliftIO m =&gt; ProcessConfig stdin stdout stderr -&gt; (Process stdin stdout stderr -&gt; m a) -&gt; m a
  </code></pre>
  
  <hr>
  
  <p>My understanding of what the function will do is, run the process, wait till  it's terminated and then run the <code>IO a</code>. However... I just noticed there is a <code>readProcess</code> function which sounds like what I should actually be using instead <a href="http://hackage.haskell.org/package/typed-process-0.2.6.0/docs/System-Process-Typed.html#v:readProcess" rel="nofollow noreferrer">http://hackage.haskell.org/package/typed-process-0.2.6.0/docs/System-Process-Typed.html#v:readProcess</a></p>
  
  <p>None the less, it would be useful to know what is actually happening in the above / <code>withProcessWait_</code>.</p>