Trying to implement immediate subscription result using VirtualTimeScheduler:
RxJS version:
5.0.0.beta.11
Code to reproduce:
import {Observable as O, VirtualTimeScheduler} from 'rxjs'
let scheduler = new VirtualTimeScheduler();
let a$ = O.interval(1000, scheduler).map(a => 'a' + a)
let b$ = O.interval(250, scheduler).map(b => 'b' + b)
let c$ = O.merge(a$, b$).take(10)
.subscribe((x) => console.log(x))
scheduler.flush()
Expected behavior:
Probably should be (this is the output without using virtual scheduler):
b0
b1
b2
a0
b3
b4
b5
b6
a1
b7
Actual behavior:
Actual output:
b0
b1
b2
Additional information:
Can be tried here
http://www.webpackbin.com/4k5VDUM5Z
This is because by default virtualTimeScheduler limits maximum frames to be executed.
Internally, virtualTimeScheduler specifies 'frame time factor' to 10 then sets maximum frame to 750 . So in above code snippet, only b$ can be included in those time frame by b$ emitted per 250, 500.. while a$ exceeds it from first emission.
For immediate workaround, I've amended snippet bit (http://www.webpackbin.com/E12aigmqb),
let scheduler = new VirtualTimeScheduler();
+//picked any suffeciently large number can include all frames expected to be executed
+scheduler.maxFrames = 75000;
let a$ = O.interval(1000, scheduler).map(a => 'a' + a);
by setting sufficiently large number of max frame to be allowed which can be done via ctor of scheduler as well.
Obviously this seems bit unergonomic, maybe revising interface bit more strictly to give notion to users would be better like
//maxFrame need to be set per each instance creation
constructor(public maxFrames: number, SchedulerAction: typeof AsyncAction = VirtualAction)
or vice versa. (or simply set default to positive infinity?)
or simply set default to positive infinity?
Why not? =)
Why not? =)
: Maybe, maybe not - I'm just not 100% sure if there's reasonable background history of choosing specific number as max frames. I'll leave this issue opened for further discussion.
This is a bug. The TestScheduler should be limited to a specific window of time.. but the VirtualTimeScheduler should not.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
This is a bug. The TestScheduler should be limited to a specific window of time.. but the VirtualTimeScheduler should not.