mostjs / core

Most.js core event stream
http://mostcore.rtfd.io
MIT License
402 stars 36 forks source link

I can't get `during` to work with window streams created using `until` #657

Closed micahscopes closed 2 years ago

micahscopes commented 2 years ago

I'm having trouble using during with a time window stream created using until. This works fine:

periodic(1)
|> during(
  at(0, at(5))
) ...

however using various window streams derived from until doesn't seem to work for me:

periodic(1)
|> during(
  never() |> until(at(5))
) ...
TylorS commented 2 years ago

Hey @micahscopes, I think the key difference between the first and second example is the first creates a higher-order stream (a stream of streams) whereas the second example does not. During utilizes the higher-order nature to determine when to start subscribing (when the "inner" stream has been emitted) and then when to stop when the "inner" stream has emitted its own value.

I hope that helps to understand the difference

micahscopes commented 2 years ago

Oh wow... that makes sense, and yes that did it. I changed the second example to the following and it worked as intended:

periodic(1)
|> during(
  never() |> until(at(5)) |> now
) ...