From 820351f800689e43073b7855711795f4994f9f89 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 13 May 2024 14:42:23 -0500 Subject: [PATCH] fix: more yields --- src/Pipes.Node.Stream.purs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Pipes.Node.Stream.purs b/src/Pipes.Node.Stream.purs index c6f0066..2de43db 100644 --- a/src/Pipes.Node.Stream.purs +++ b/src/Pipes.Node.Stream.purs @@ -94,17 +94,21 @@ fromTransform t = liftEffect $ removeErrorListener fromReadable t pure $ Done unit - yieldFromReadableHalf = 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 + yieldFromReadableHalf = + flip tailRecM unit $ const do + res <- liftEffect (O.read t) + case res of + 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