fix: more yields

This commit is contained in:
orion 2024-05-13 14:42:23 -05:00
parent 9d8b500b8d
commit 820351f800
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -94,17 +94,21 @@ fromTransform t =
liftEffect $ removeErrorListener
fromReadable t
pure $ Done unit
yieldFromReadableHalf = do
yieldFromReadableHalf =
flip tailRecM unit $ const do
res <- liftEffect (O.read t)
case res of
O.ReadJust a -> yield (Just a) *> yieldFromReadableHalf
O.ReadWouldBlock -> pure unit
O.ReadClosed -> yield Nothing *> pure unit
O.ReadJust a -> do
yield $ Just a
pure $ Loop unit
O.ReadWouldBlock -> pure $ Done unit
O.ReadClosed -> yield Nothing $> Done unit
go { error, cancel } = do
liftAff $ delay $ wrap 0.0
err <- liftEffect $ liftST $ STRef.read error
for_ err throwError
yieldFromReadableHalf
ma <- await
case ma of
Nothing -> cleanup cancel