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