-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5513218
commit ebd55e4
Showing
5 changed files
with
80 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vscode | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# Ticker | ||
A javascript Ticker which ticks well in inactive tab. | ||
# Timer | ||
A javascript Timer which works well in inactive tab. | ||
|
||
### Why I write this library? | ||
Most of the modern browsers throttled [setTimeout/setInterval](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Reasons_for_delays_longer_than_specified) to more than 1000ms if the page's inactive. In most of the cases, it saves CPU loads while the tabs are inactive, which's a good thing. But in some extreme cases (like sending heart beating packet), it requires the page to have a stable timer. | ||
I've tried to search if there's any methods to prevent browsers throttling timers, but so far it seems like [WebWorker](https://developer.mozilla.org/en/docs/Web/API/Web_Workers_API/Using_web_workers) could be the only solution to prevent throttling. | ||
|
||
### How to use it? | ||
``` | ||
// Instanize the Timer. | ||
let T = new Timer(); | ||
// The same API as window.setTimeout/window.setInterval | ||
T.setTimeout(fn, delay, ...params); | ||
T.setInterval(fn, delay, ...params); | ||
T.clearTimeout(timeoutID); | ||
T.clearInterval(intervalID); | ||
// These are newly added | ||
T.hasTimer(timerID) | ||
T.clearAll() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"name": "ticker", | ||
"name": "timers", | ||
"version": "1.0.0", | ||
"description": "A javascript ticker which ticks well in inactive tabs", | ||
"description": "A javascript timers which works well in inactive tabs", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ZixiaoWang/Ticker.git" | ||
"url": "git+https://github.com/ZixiaoWang/Timer.git" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
|
@@ -17,7 +17,7 @@ | |
"author": "[email protected]", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ZixiaoWang/Ticker/issues" | ||
"url": "https://github.com/ZixiaoWang/Timer/issues" | ||
}, | ||
"homepage": "https://github.com/ZixiaoWang/Ticker#readme" | ||
"homepage": "https://github.com/ZixiaoWang/Timer#readme" | ||
} |