fix: timeslice shenanigans

This commit is contained in:
orion 2024-05-03 15:51:45 -05:00
parent bf7404fe59
commit bbb78e2d95
Signed by: orion
GPG Key ID: 6D4165AE4C928719
3 changed files with 96 additions and 5 deletions

View File

@ -16,6 +16,7 @@ workspace:
- foreign: ">=7.0.0 <8.0.0"
- foreign-object: ">=4.1.0 <5.0.0"
- integers: ">=6.0.0 <7.0.0"
- js-timers
- lists: ">=7.0.0 <8.0.0"
- maybe: ">=6.0.0 <7.0.0"
- newtype: ">=5.0.0 <6.0.0"
@ -34,6 +35,7 @@ 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
@ -42,6 +44,7 @@ workspace:
- arraybuffer-types
- arrays
- bifunctors
- catenable-lists
- console
- const
- contravariant
@ -60,6 +63,8 @@ workspace:
- foreign
- foreign-object
- formatters
- free
- freet
- functions
- functors
- gen
@ -67,9 +72,11 @@ workspace:
- integers
- invariant
- js-date
- js-timers
- lazy
- lists
- maybe
- monad-control
- newtype
- node-buffer
- node-event-emitter
@ -99,6 +106,7 @@ workspace:
- typelevel-prelude
- unfoldable
- unicode
- unlift
- unsafe-coerce
extra_packages: {}
packages:
@ -158,6 +166,18 @@ 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
@ -351,6 +371,40 @@ 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
@ -425,6 +479,12 @@ packages:
- foreign
- integers
- now
js-timers:
type: registry
version: 6.1.0
integrity: sha256-znHWLSSOYw15P5DTcsAdal2lf7nGA2yayLdOZ2t5r7o=
dependencies:
- effect
lazy:
type: registry
version: 6.0.0
@ -460,6 +520,15 @@ 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
@ -783,6 +852,23 @@ 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

View File

@ -10,6 +10,7 @@ package:
strict: true
pedanticPackages: true
dependencies:
- js-timers
- aff: ">=7.1.0 <8.0.0"
- arrays: ">=7.3.0 <8.0.0"
- bifunctors: ">=6.0.0 <7.0.0"

View File

@ -25,6 +25,7 @@ import Effect.Aff (Canceler(..), makeAff)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Effect.Timer (setTimeout)
import Effect.Uncurried (mkEffectFn1)
import Foreign (Foreign, unsafeToForeign)
import Foreign.Object (Object)
@ -122,13 +123,16 @@ foreach stream cb = do
liftAff $ makeAff \res -> do
removeDataListener <- flip (Event.on dataH) stream \row ->
flip catchError (res <<< Left) do
void
$ setTimeout 0
$ 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)
removeErrorListener <- flip (Event.once Stream.errorH) stream (res <<< Left)
pure $ Canceler $ const $ liftEffect do
removeDataListener