fix: do not busy loop

This commit is contained in:
orion 2024-05-03 10:44:37 -05:00
parent eab713cd4e
commit 616ceabd9f
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 3 additions and 3 deletions

View File

@ -15,7 +15,7 @@ workspace:
- foldable-traversable: ">=6.0.0 <7.0.0"
- foreign: ">=7.0.0 <8.0.0"
- foreign-object: ">=4.1.0 <5.0.0"
- fork
- fork: ">=6.0.0 <7.0.0"
- integers: ">=6.0.0 <7.0.0"
- lists: ">=7.0.0 <8.0.0"
- maybe: ">=6.0.0 <7.0.0"
@ -26,7 +26,7 @@ workspace:
- nullable: ">=6.0.0 <7.0.0"
- numbers: ">=9.0.1 <10.0.0"
- ordered-collections: ">=3.2.0 <4.0.0"
- parallel
- parallel: ">=6.0.0 <7.0.0"
- precise-datetime: ">=7.0.0 <8.0.0"
- prelude: ">=6.0.1 <7.0.0"
- record: ">=4.0.0 <5.0.0"

View File

@ -100,12 +100,12 @@ parse config csv = do
-- | Loop until the stream is closed, invoking the callback with each record as it is parsed.
foreach :: forall @r rl x m f p. Parallel p m => Alternative p => MonadFork f m => MonadRec m => MonadAff m => RowToList r rl => ReadCSVRecord r rl => CSVParser r x -> ({ | r } -> m Unit) -> m Unit
foreach stream cb = whileJust do
liftAff $ delay $ wrap 0.0
isReadable <- liftEffect $ Stream.readable stream
liftAff $ when (not isReadable) $ makeAff \res -> do
stop <- flip (Event.once Stream.readableH) stream $ res $ Right unit
pure $ Canceler $ const $ liftEffect stop
fibers <- flip tailRecM [] \fibers -> do
liftAff $ delay $ wrap 0.0
r <- liftEffect $ read @r stream
case r of
Just r' -> do