Skip to content
Browse files

Update schedule not more than once per minute

Refs #1
  • Loading branch information...
1 parent 15df728 commit f90a63fae06db9fd6dbbd52f9c92fa81f229f724 @alexeykuzmin committed Oct 26, 2013
Showing with 25 additions and 1 deletion.
  1. +25 −1 src/background.js
View
26 src/background.js
@@ -167,5 +167,29 @@
return window.localStorage.getItem("rasp");
}
- window.setInterval(refreshSchedule, 10000);
+ /**
+ * @return {number} Integer number of seconds till next minute [1; 60].
+ */
+ function getNumberOfSecondsTillNextMinute() {
+ var nowDate = new Date();
+ return 60 - nowDate.getSeconds();
+ }
+
+ function init() {
+ // Update now.
+ refreshSchedule();
+
+ // Update on next minute start.
+ setTimeout(function() {
+ refreshSchedule();
+
+ // And every minute after.
+ setInterval(refreshSchedule, 60 * 1000);
+
+ // XXX(alexeykuzmin): `chrome.alarms` fires events not very precisely.
+ }, getNumberOfSecondsTillNextMinute() * 1000);
+ }
+
+ init();
+
})(window, chrome);

0 comments on commit f90a63f

Please sign in to comment.
Something went wrong with that request. Please try again.