
Untitled
By: a guest on
May 15th, 2012 | syntax:
None | size: 0.67 KB | hits: 13 | expires: Never
How to create an ever-retrying Enumerator
enumConnectAgain :: forall b m. MonadIO m => IO Handle -> Enumerator ByteString m b
enumConnectAgain open step =
fix $ again -> do
mh <- liftIO (Ex.try open)
case mh of
Left (ex :: SomeException) -> again
Right h -> loop h step
where
loop :: Handle -> Step ByteString m b -> Iteratee ByteString m b
loop h step@(Continue k) = do
mstr <- liftIO (Ex.try $ B.hGetSome h 1024)
case mstr of
Left (ex :: SomeException) -> enumConnectAgain open step
Right str -> k (Chunks [str]) >>== loop h
loop h step = returnI step