Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created May 28, 2014 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwotton/ffa6dfb73fe3b0a8ef9b to your computer and use it in GitHub Desktop.
Save mwotton/ffa6dfb73fe3b0a8ef9b to your computer and use it in GitHub Desktop.
mvarEnumerator :: (MonadIO m, ToJSON a1) => (Async a, MVar a1) -> Step Builder m b -> Iteratee Builder m b
mvarEnumerator (task,mvar) step = case step of
Yield a b -> Iteratee . return . Yield a $ b
Continue s -> do
r' <- liftIO $ race (wait task) (takeMVar mvar)
s $ case r' of
Left _ -> EOF
Right r -> Chunks [fromLazyByteString $ encode r]
Error s -> error (show s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment