Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get immediate subscription result using VirtualTimeScheduler #1889

Closed
wclr opened this issue Aug 21, 2016 · 6 comments · Fixed by #1893
Closed

How to get immediate subscription result using VirtualTimeScheduler #1889

wclr opened this issue Aug 21, 2016 · 6 comments · Fixed by #1893
Labels
bug Confirmed bug

Comments

@wclr
Copy link

wclr commented Aug 21, 2016

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

@kwonoj
Copy link
Member

kwonoj commented Aug 21, 2016

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.

@kwonoj
Copy link
Member

kwonoj commented Aug 21, 2016

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?)

@wclr
Copy link
Author

wclr commented Aug 21, 2016

or simply set default to positive infinity?

Why not? =)

@kwonoj
Copy link
Member

kwonoj commented Aug 21, 2016

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.

@benlesh
Copy link
Member

benlesh commented Aug 21, 2016

This is a bug. The TestScheduler should be limited to a specific window of time.. but the VirtualTimeScheduler should not.

@benlesh benlesh added the bug Confirmed bug label Aug 21, 2016
kwonoj pushed a commit to kwonoj/rxjs that referenced this issue Aug 22, 2016
kwonoj added a commit to kwonoj/rxjs that referenced this issue Aug 22, 2016
blakef pushed a commit to blakef/rxjs that referenced this issue Aug 23, 2016
@lock
Copy link

lock bot commented Jun 7, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants