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

View File

@ -10,6 +10,7 @@ package:
strict: true strict: true
pedanticPackages: true pedanticPackages: true
dependencies: dependencies:
- js-timers
- aff: ">=7.1.0 <8.0.0" - aff: ">=7.1.0 <8.0.0"
- arrays: ">=7.3.0 <8.0.0" - arrays: ">=7.3.0 <8.0.0"
- bifunctors: ">=6.0.0 <7.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.Aff.Class (class MonadAff, liftAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Exception (error) import Effect.Exception (error)
import Effect.Timer (setTimeout)
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import Foreign (Foreign, unsafeToForeign) import Foreign (Foreign, unsafeToForeign)
import Foreign.Object (Object) import Foreign.Object (Object)
@ -122,13 +123,16 @@ foreach stream cb = do
liftAff $ makeAff \res -> do liftAff $ makeAff \res -> do
removeDataListener <- flip (Event.on dataH) stream \row -> 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 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
flip catchError (liftEffect <<< res <<< Left) (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.once Stream.errorH) stream (res <<< Left)
pure $ Canceler $ const $ liftEffect do pure $ Canceler $ const $ liftEffect do
removeDataListener removeDataListener