wip: explore removing delays(8)

This commit is contained in:
orion 2024-05-14 11:08:46 -05:00
parent edc7d40dbc
commit f9c0e20777
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -13,6 +13,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (liftEffect)
import Effect.Exception (Error)
import Node.Stream.Object (needsDrain)
import Node.Stream.Object as O
import Pipes (await, yield)
import Pipes (for) as P
@ -108,7 +109,12 @@ fromTransform t =
err <- liftEffect $ liftST $ STRef.read error
for_ err throwError
needsDrain <- liftEffect $ O.needsDrain t
if needsDrain then do
liftAff $ O.awaitReadableOrClosed t
yieldWhileReadable
pure $ Loop {error, cancel}
else do
ma <- await
case ma of
Nothing -> cleanup cancel
@ -120,10 +126,7 @@ fromTransform t =
maybeYield1
pure $ Loop { error, cancel }
O.WriteWouldBlock -> do
queueLen <- liftEffect $ O.readableLength t
when (queueLen == 0) $ liftAff $ O.awaitReadableOrClosed t
yieldWhileReadable
liftAff $ O.awaitWritableOrClosed t
pure $ Loop { error, cancel }
in
do