fix: effect cb
This commit is contained in:
parent
35bd75fadf
commit
6d41852361
78
spago.lock
78
spago.lock
@ -34,7 +34,6 @@ workspace:
|
||||
- tailrec: ">=6.1.0 <7.0.0"
|
||||
- transformers: ">=6.0.0 <7.0.0"
|
||||
- typelevel-prelude: ">=7.0.0 <8.0.0"
|
||||
- unlift: ">=1.0.1 <2.0.0"
|
||||
- unsafe-coerce: ">=6.0.0 <7.0.0"
|
||||
test_dependencies:
|
||||
- console
|
||||
@ -43,7 +42,6 @@ workspace:
|
||||
- arraybuffer-types
|
||||
- arrays
|
||||
- bifunctors
|
||||
- catenable-lists
|
||||
- console
|
||||
- const
|
||||
- contravariant
|
||||
@ -62,8 +60,6 @@ workspace:
|
||||
- foreign
|
||||
- foreign-object
|
||||
- formatters
|
||||
- free
|
||||
- freet
|
||||
- functions
|
||||
- functors
|
||||
- gen
|
||||
@ -74,7 +70,6 @@ workspace:
|
||||
- lazy
|
||||
- lists
|
||||
- maybe
|
||||
- monad-control
|
||||
- newtype
|
||||
- node-buffer
|
||||
- node-event-emitter
|
||||
@ -104,7 +99,6 @@ workspace:
|
||||
- typelevel-prelude
|
||||
- unfoldable
|
||||
- unicode
|
||||
- unlift
|
||||
- unsafe-coerce
|
||||
extra_packages: {}
|
||||
packages:
|
||||
@ -164,18 +158,6 @@ packages:
|
||||
- newtype
|
||||
- prelude
|
||||
- tuples
|
||||
catenable-lists:
|
||||
type: registry
|
||||
version: 7.0.0
|
||||
integrity: sha256-76vYENhwF4BWTBsjeLuErCH2jqVT4M3R1HX+4RwSftA=
|
||||
dependencies:
|
||||
- control
|
||||
- foldable-traversable
|
||||
- lists
|
||||
- maybe
|
||||
- prelude
|
||||
- tuples
|
||||
- unfoldable
|
||||
console:
|
||||
type: registry
|
||||
version: 6.1.0
|
||||
@ -369,40 +351,6 @@ packages:
|
||||
- parsing
|
||||
- prelude
|
||||
- transformers
|
||||
free:
|
||||
type: registry
|
||||
version: 7.1.0
|
||||
integrity: sha256-JAumgEsGSzJCNLD8AaFvuX7CpqS5yruCngi6yI7+V5k=
|
||||
dependencies:
|
||||
- catenable-lists
|
||||
- control
|
||||
- distributive
|
||||
- either
|
||||
- exists
|
||||
- foldable-traversable
|
||||
- invariant
|
||||
- lazy
|
||||
- maybe
|
||||
- prelude
|
||||
- tailrec
|
||||
- transformers
|
||||
- tuples
|
||||
- unsafe-coerce
|
||||
freet:
|
||||
type: registry
|
||||
version: 7.0.0
|
||||
integrity: sha256-zkL6wU4ZPq8xz1kGFxoliWqyhBksepMJTyA68VEBaJo=
|
||||
dependencies:
|
||||
- aff
|
||||
- bifunctors
|
||||
- effect
|
||||
- either
|
||||
- exists
|
||||
- free
|
||||
- prelude
|
||||
- tailrec
|
||||
- transformers
|
||||
- tuples
|
||||
functions:
|
||||
type: registry
|
||||
version: 6.0.0
|
||||
@ -512,15 +460,6 @@ packages:
|
||||
- invariant
|
||||
- newtype
|
||||
- prelude
|
||||
monad-control:
|
||||
type: registry
|
||||
version: 5.0.0
|
||||
integrity: sha256-bgfDW30wbIm70NR1Tvvh9P+VFQMDh1wK2sSJXCj/dZc=
|
||||
dependencies:
|
||||
- aff
|
||||
- freet
|
||||
- identity
|
||||
- lists
|
||||
newtype:
|
||||
type: registry
|
||||
version: 5.0.0
|
||||
@ -844,23 +783,6 @@ packages:
|
||||
- foldable-traversable
|
||||
- maybe
|
||||
- strings
|
||||
unlift:
|
||||
type: registry
|
||||
version: 1.0.1
|
||||
integrity: sha256-nbBCVV0fZz/3UHKoW11dcTwBYmQOIgK31ht2BN47RPw=
|
||||
dependencies:
|
||||
- aff
|
||||
- effect
|
||||
- either
|
||||
- freet
|
||||
- identity
|
||||
- lists
|
||||
- maybe
|
||||
- monad-control
|
||||
- prelude
|
||||
- st
|
||||
- transformers
|
||||
- tuples
|
||||
unsafe-coerce:
|
||||
type: registry
|
||||
version: 6.0.0
|
||||
|
@ -18,13 +18,11 @@ import Data.Filterable (filter)
|
||||
import Data.Map (Map)
|
||||
import Data.Map as Map
|
||||
import Data.Maybe (Maybe(..), isNothing)
|
||||
import Data.Newtype (wrap)
|
||||
import Data.Nullable (Nullable)
|
||||
import Data.Nullable as Nullable
|
||||
import Effect (Effect)
|
||||
import Effect.Aff (Canceler(..), delay, launchAff_, makeAff)
|
||||
import Effect.Aff (Canceler(..), makeAff)
|
||||
import Effect.Aff.Class (class MonadAff, liftAff)
|
||||
import Effect.Aff.Unlift (class MonadUnliftAff, UnliftAff(..), askUnliftAff)
|
||||
import Effect.Class (liftEffect)
|
||||
import Effect.Exception (error)
|
||||
import Effect.Uncurried (mkEffectFn1)
|
||||
@ -90,8 +88,7 @@ make = makeImpl <<< unsafeToForeign <<< Object.union (recordToForeign { columns:
|
||||
-- | Synchronously parse a CSV string
|
||||
parse
|
||||
:: forall @r rl @config missing extra m
|
||||
. MonadUnliftAff m
|
||||
=> MonadAff m
|
||||
. MonadAff m
|
||||
=> RowToList r rl
|
||||
=> ReadCSVRecord r rl
|
||||
=> Union config missing (Config extra)
|
||||
@ -107,16 +104,13 @@ 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
|
||||
. MonadUnliftAff m
|
||||
=> MonadAff m
|
||||
. MonadAff m
|
||||
=> RowToList r rl
|
||||
=> ReadCSVRecord r rl
|
||||
=> CSVParser r x
|
||||
-> ({ | r } -> m Unit)
|
||||
-> ({ | r } -> Effect Unit)
|
||||
-> m Unit
|
||||
foreach stream cb = do
|
||||
UnliftAff unlift <- askUnliftAff
|
||||
|
||||
alreadyHaveCols <- liftEffect $ getOrInitColumnsMap stream
|
||||
when (isNothing alreadyHaveCols)
|
||||
$ liftAff
|
||||
@ -127,12 +121,12 @@ foreach stream cb = do
|
||||
pure $ Canceler $ const $ liftEffect stop
|
||||
|
||||
liftAff $ makeAff \res -> do
|
||||
removeDataListener <- flip (Event.on dataH) stream \row -> launchAff_ $ delay (wrap 1.0) <* liftEffect
|
||||
( flip catchError (res <<< Left) do
|
||||
cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream
|
||||
record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row
|
||||
launchAff_ $ flip catchError (liftEffect <<< res <<< Left) (unlift $ cb record)
|
||||
)
|
||||
removeDataListener <- flip (Event.on dataH) stream \row ->
|
||||
flip catchError (res <<< Left) do
|
||||
cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream
|
||||
record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row
|
||||
flip catchError (liftEffect <<< res <<< Left) (cb record)
|
||||
|
||||
removeEndListener <- flip (Event.once Stream.endH) stream (res $ Right unit)
|
||||
removeErrorListener <- flip (Event.on Stream.errorH) stream (res <<< Left)
|
||||
|
||||
@ -160,8 +154,7 @@ read stream = runMaybeT do
|
||||
-- | Collect all parsed records into an array
|
||||
readAll
|
||||
:: forall @r rl a m
|
||||
. MonadUnliftAff m
|
||||
=> MonadAff m
|
||||
. MonadAff m
|
||||
=> RowToList r rl
|
||||
=> ReadCSVRecord r rl
|
||||
=> CSVParser r a
|
||||
|
Loading…
Reference in New Issue
Block a user