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

Observable.interval in inactive tab work different than plain js setInterval() #3042

Closed
nshikov opened this issue Nov 3, 2017 · 8 comments · Fixed by Xenira/Shashki#66
Closed

Comments

@nshikov
Copy link

nshikov commented Nov 3, 2017

Observable.interval in inactive tab work different than plain js setInterval()

Open http://jsbin.com/muvaqipaqa/1/edit?html,js,console,output
See 'i:0', 'j:0', ... in console. Switch to another browser tab for 30 seconds or so. Switch back to jsbin tab. See that i have much more different value than j

RxJS version:
5.5.2

Code to reproduce:
http://jsbin.com/muvaqipaqa/1/edit?html,js,console,output

Expected behavior:
i and j have same values
Actual behavior:
i and j have different values

@kwonoj
Copy link
Member

kwonoj commented Nov 3, 2017

you can't expect interval observable works identical to setInterval as interval observable have scheduling to create inverval values.

this seems browser implementation does try to prevent js execution in background for inactive tabs. I'm not sure devtools allows to disable it - if it's possible, please check with it to confirm.
Reopened for further digging.

@kwonoj kwonoj closed this as completed Nov 3, 2017
@nshikov
Copy link
Author

nshikov commented Nov 3, 2017

@kwonoj Rly? So if Observable.interval will be called after 1500 ms instead of expected 1000 ms this is fine?
You mean I should not expect Observable.interval to work correctly in browsers?
I'm pretty sure this is an issue with rxjs implementation...

@nshikov
Copy link
Author

nshikov commented Nov 3, 2017

If you check it in jsbin with RxJs 5.0.3 it works as expected, in 5.5.2 it doesn't!
Please reopen the issue.

@kwonoj
Copy link
Member

kwonoj commented Nov 3, 2017

hmm, yeah that sounds odd. I thought it's happening all time.

@kwonoj kwonoj reopened this Nov 3, 2017
@kwonoj
Copy link
Member

kwonoj commented Nov 3, 2017

Reopened.

cartant added a commit to cartant/rxjs that referenced this issue Nov 4, 2017
In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes ReactiveX#3042
cartant added a commit to cartant/rxjs that referenced this issue Nov 4, 2017
In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes ReactiveX#3042
@benlesh
Copy link
Member

benlesh commented Nov 8, 2017

You need to be careful relying on setInterval, setTimeout, etc in JSBin, I've seen some odd behavior there, and I think it's being patched or hooked in some way by JSBin.

@nshikov
Copy link
Author

nshikov commented Nov 8, 2017

Thanks for the hint! I will pay attention to it.
Anyway I initially found the issue on my local environment, just added example to jsbin.

cartant added a commit to cartant/rxjs that referenced this issue Nov 9, 2017
In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes ReactiveX#3042
cartant added a commit to cartant/rxjs that referenced this issue Nov 12, 2017
In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes ReactiveX#3042
@benlesh benlesh closed this as completed in 7d722d4 Dec 1, 2017
cartant added a commit to cartant/rxjs that referenced this issue Jan 13, 2018
In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes ReactiveX#3042
benlesh pushed a commit that referenced this issue Jan 16, 2018
* test(scheduler): add interval recycling tests

* fix(scheduler): prevent unwanted clearInterval

In AsyncAction, this.pending was assigned before the call to
recycleAsyncId. That prevented the interval from being re-used resulting
in the interval being cleared and re-created for each notification.

Closes #3042
@lock
Copy link

lock bot commented Jun 6, 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 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants