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(0) locks up browser incorrectly #1339

Closed
jayphelps opened this issue Feb 12, 2016 · 5 comments
Closed

Observable.interval(0) locks up browser incorrectly #1339

jayphelps opened this issue Feb 12, 2016 · 5 comments
Labels
bug Confirmed bug help wanted Issues we wouldn't mind assistance with.

Comments

@jayphelps
Copy link
Member

This code:

Observable.interval(0)
  .throttleTime(1000)
  .subscribe(item => console.log(item));

Should not lock up the browser, because using a setInterval(func, 0) won't, as long as the func isn't crazy.

If you change it to Observable.interval(1), it works as expected, so @Blesh thinks it probably is trying to be overly smart and instead do a regular for loop or equivalent blocking operation.

https://jsbin.com/qiperi/edit?js,console,output (example here uses .interval(1) to not lock up your browser immediately, but if you change it to 0 it will lock up)

@jayphelps
Copy link
Member Author

Guessing it has something to do with using AsapScheduler and that scheduler exec immediately if delay is 0.

https://github.com/ReactiveX/RxJS/blob/59a8c186138ddb1b8fcf2a6e1ab80a87812f78a2/src/scheduler/AsapAction.ts#L8

Without knowing enough about why each scheduler exists, it seems to me like .interval() should use a FutureScheduler (that uses FutureAction) but that doesn't exist atm.

@benlesh benlesh added bug Confirmed bug help wanted Issues we wouldn't mind assistance with. labels Feb 12, 2016
@trxcllnt
Copy link
Member

@jayphelps Observable.interval defaults to Scheduler.asap, which schedules actions with delay <= 0 using setImmediate (or equivalent for the environment). I understand microtasks do block the event loop. We are in need of a Scheduler.async impl that always returns a FutureAction from Scheduler.prototype.scheduleNow (similar to Scheduler.asap).

@benlesh
Copy link
Member

benlesh commented Feb 14, 2016

I understand microtasks do block the event loop.

Oh yeah. Derp. If your schedule an infinite loop of micro tasks, everything you schedule has to run before anything else on the event loop. As such it'll block for anything you're not scheduling as a micro task. LOL. Makes total sense.

@benlesh
Copy link
Member

benlesh commented Feb 14, 2016

This should probably default to a different scheduler. Leaving it as a bug for now.

@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 help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

No branches or pull requests

3 participants