fix: timeslice shenanigans
This commit is contained in:
parent
a3625ab1b7
commit
07c86f096f
@ -3,6 +3,7 @@ module Node.Stream.CSV.Parse where
|
|||||||
import Prelude hiding (join)
|
import Prelude hiding (join)
|
||||||
|
|
||||||
import Control.Alt ((<|>))
|
import Control.Alt ((<|>))
|
||||||
|
import Control.Alternative (guard)
|
||||||
import Control.Monad.Error.Class (liftEither)
|
import Control.Monad.Error.Class (liftEither)
|
||||||
import Control.Monad.Except (runExcept)
|
import Control.Monad.Except (runExcept)
|
||||||
import Control.Monad.Maybe.Trans (MaybeT(..), runMaybeT)
|
import Control.Monad.Maybe.Trans (MaybeT(..), runMaybeT)
|
||||||
@ -20,12 +21,13 @@ import Data.Filterable (filter)
|
|||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import Data.Map as Map
|
import Data.Map as Map
|
||||||
import Data.Maybe (Maybe(..), isNothing)
|
import Data.Maybe (Maybe(..), isNothing)
|
||||||
|
import Data.Newtype (wrap)
|
||||||
import Data.Nullable (Nullable)
|
import Data.Nullable (Nullable)
|
||||||
import Data.Nullable as Nullable
|
import Data.Nullable as Nullable
|
||||||
import Data.Traversable (for)
|
import Data.Traversable (for)
|
||||||
import Effect (Effect)
|
import Effect (Effect)
|
||||||
import Effect as Effect
|
import Effect as Effect
|
||||||
import Effect.Aff (Canceler(..), makeAff)
|
import Effect.Aff (Canceler(..), delay, makeAff)
|
||||||
import Effect.Aff.Class (class MonadAff, liftAff)
|
import Effect.Aff.Class (class MonadAff, liftAff)
|
||||||
import Effect.Class (liftEffect)
|
import Effect.Class (liftEffect)
|
||||||
import Effect.Exception (error)
|
import Effect.Exception (error)
|
||||||
@ -120,7 +122,14 @@ foreach
|
|||||||
=> CSVParser r x
|
=> CSVParser r x
|
||||||
-> ({ | r } -> m Unit)
|
-> ({ | r } -> m Unit)
|
||||||
-> m Unit
|
-> m Unit
|
||||||
foreach stream cb = whileJust do
|
foreach stream cb =
|
||||||
|
whileJust
|
||||||
|
$ runMaybeT
|
||||||
|
$ do
|
||||||
|
liftAff $ delay $ wrap 0.0
|
||||||
|
|
||||||
|
guard =<< not <$> liftEffect (Stream.closed stream)
|
||||||
|
|
||||||
isReadable <- liftEffect $ Stream.readable stream
|
isReadable <- liftEffect $ Stream.readable stream
|
||||||
liftAff $ when (not isReadable) $ makeAff \res -> do
|
liftAff $ when (not isReadable) $ makeAff \res -> do
|
||||||
stop <- flip (Event.once Stream.readableH) stream $ res $ Right unit
|
stop <- flip (Event.once Stream.readableH) stream $ res $ Right unit
|
||||||
@ -133,9 +142,9 @@ foreach stream cb = whileJust do
|
|||||||
pure $ isNothing r
|
pure $ isNothing r
|
||||||
records <- liftEffect $ ST.toEffect $ Array.ST.unsafeFreeze recordsST
|
records <- liftEffect $ ST.toEffect $ Array.ST.unsafeFreeze recordsST
|
||||||
|
|
||||||
parTraverse_ cb records
|
lift $ parTraverse_ cb records
|
||||||
isClosed <- liftEffect $ Stream.closed stream
|
guard =<< not <$> liftEffect (Stream.closed stream)
|
||||||
pure $ if isClosed then Nothing else Just unit
|
pure unit
|
||||||
|
|
||||||
-- | Reads a parsed record from the stream.
|
-- | Reads a parsed record from the stream.
|
||||||
-- |
|
-- |
|
||||||
|
Loading…
Reference in New Issue
Block a user