Closed Pet3ris closed 4 years ago
It was pretty tricky to make swotchMap
behave well. You can see lots of compliance tests around operators and it took a while to make them all pass for this particular operator. It's possible that there's an edge case being triggered here, but I'm not quite sure which part it may be.
It could be the internal queue maybe, since the source it uses emits only a single value after a tick, but that value will immediately have a Push
and an End
event.
Actually, have you checked whether it's state.looping = false
being missing in your source?
You may want to add that: https://github.com/kitten/wonka/blob/c1108636590327f5648095d1b44fb17f9c93f0a7/src/Wonka_sources.re#L70
I used to have a built in trampoline factory. Maybe it's time to add it back 😅
@kitten You're a legend - everything works!
I see! So I suppose as concatMap
was waiting for the promise source to resolve, when it was pulling again the source was stuck in a looping state which didn't allow it to push anymore, while mergeMap
would eagerly pull, which allowed the promises to just resolve in order. That makes sense 😅
Glad this is resolved! I should probably add iterate
to the built-in sources (Great Name btw!)
@kitten definitely feel free to, name taken from Haskell ;)! In terms of the API, I wonder if there's a general iterable constructor that would be useful, something like makeIterable: (unit => option('a)) => streamT('a)
.
Hi There,
I've added two extensions to Wonka that potentially highlight an incompatibility between
concatMap
andmergeMap
.iterate
A new source that represents a potentially infinite generator from a starting value and an iteration step. Analogous to Haskell'siterate
(https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v:iterate) but with optional termination.downTo
An operator for getting numbers start, start - 1, ... down to a provided bound. E.g.,downTo(3, 1)
would produce[|3, 2, 1|]
in a stream.toArrayAsync
A sink that captures all stream values in an array, wrapped up in a promise. This fixestoArray
to work with asynchronous streams.Some tests to demonstrate how these work:
The issue
Finally, here is a description of the issue. Below is a test that times out (
concatMap
fails to collect any values). It times out:If I replace
concatMap
withmergeMap
, this test succeeds.Any thoughts on why
concatMap
is skipping these values?Tests use
bs-jest
.