BackburnerJS / backburner.js

A rewrite of the Ember.js run loop as a generic microlibrary
MIT License
392 stars 80 forks source link

Always reinstall timers #355

Closed kanongil closed 5 years ago

kanongil commented 5 years ago

This patch fixes the issues in #353 & #354. I don't think there is a better way to solve it, that handles all corner cases.

Note that there is still an issue when "time travel" happens, but no new timers are installed. Ideally, browsers would provide an event when this happens, but this is not the case.

The best workaround would probably be to add a hook to the visibilitychange event, and call _reinstallTimerTimeout() when document.visibilityState === 'visible'. Unfortunately, this is also called on tab switches, and wouldn't trigger for a tab that is already 'hidden' (until it is made visible).

kanongil commented 5 years ago

Of further note, this sleep/timer/later issue is probably the cause of some weird behaviour I occasionally experience in my Ember app, but haven't been able to understand.

krisselden commented 5 years ago

@kanongil you've tested that this does fix the issue?

kanongil commented 5 years ago

It fixes the most critical part of the issue, namely that a newly scheduled timer could have to wait very long to fire.

This is done by resetting the timeout when it could have changed due to system sleep.

kanongil commented 5 years ago

How can we get this thing rolling? Do you need anything more from me?

rwjblue commented 5 years ago

backburner.js 2.4.1 published 🎉