Issue with merging streams with debounce

I want to merge two streams, one of which is debounced. But it seems like the reading of the stream is interrupted after the first value from the debounced stream is emitted.


Here is the code:
Effect.gen(function* (_) {
  const stream1 = Stream.fromIterable([1, 2, 3, 3, 5]).pipe(
    Stream.schedule(Schedule.spaced('1 second')),
    Stream.debounce('200 millis'),
    Stream.tapErrorCause(Console.error)
  )

  const stream2 = Stream.fromIterable(['a', 'b', 'c']).pipe(
    Stream.schedule(Schedule.spaced('500 millis'))
  )

  const combined = Stream.merge(stream1, stream2)

  yield* _(Stream.runForEach(combined, (a) => Console.log(a)))
})


And I am getting this output:
a
b
1
{
  _id: 'Cause',
  _tag: 'Sequential',
  left: {
    _id: 'Cause',
    _tag: 'Sequential',
    left: { _id: 'Cause', _tag: 'Empty' },
    right: { _id: 'Cause', _tag: 'Interrupt', fiberId: [Object] }  },
  right: {
    _id: 'Cause',
    _tag: 'Sequential',
    left: { _id: 'Cause', _tag: 'Empty' },
    right: { _id: 'Cause', _tag: 'Interrupt', fiberId: [Object] }
  }
}


Can someone please explain why is the stream interrupted? When I remove the debounce, both streams are red until end...
Was this page helpful?