1 |
3a515b92
|
cagy
|
# Overview
|
2 |
|
|
|
3 |
|
|
Adds support for the `timers` module to browserify.
|
4 |
|
|
|
5 |
|
|
## Wait, isn't it already supported in the browser?
|
6 |
|
|
|
7 |
|
|
The public methods of the `timers` module are:
|
8 |
|
|
|
9 |
|
|
* `setTimeout(callback, delay, [arg], [...])`
|
10 |
|
|
* `clearTimeout(timeoutId)`
|
11 |
|
|
* `setInterval(callback, delay, [arg], [...])`
|
12 |
|
|
* `clearInterval(intervalId)`
|
13 |
|
|
|
14 |
|
|
and indeed, browsers support these already.
|
15 |
|
|
|
16 |
|
|
## So, why does this exist?
|
17 |
|
|
|
18 |
|
|
The `timers` module also includes some private methods used in other built-in
|
19 |
|
|
Node.js modules:
|
20 |
|
|
|
21 |
|
|
* `enroll(item, delay)`
|
22 |
|
|
* `unenroll(item)`
|
23 |
|
|
* `active(item)`
|
24 |
|
|
|
25 |
|
|
These are used to efficiently support a large quantity of timers with the same
|
26 |
|
|
timeouts by creating only a few timers under the covers.
|
27 |
|
|
|
28 |
|
|
Node.js also offers the `immediate` APIs, which aren't yet available cross-browser, so we polyfill those:
|
29 |
|
|
|
30 |
|
|
* `setImmediate(callback, [arg], [...])`
|
31 |
|
|
* `clearImmediate(immediateId)`
|
32 |
|
|
|
33 |
|
|
## I need lots of timers and want to use linked list timers as Node.js does.
|
34 |
|
|
|
35 |
|
|
Linked lists are efficient when you have thousands (millions?) of timers with the same delay.
|
36 |
|
|
Take a look at [timers-browserify-full](https://www.npmjs.com/package/timers-browserify-full) in this case.
|
37 |
|
|
|
38 |
|
|
# License
|
39 |
|
|
|
40 |
|
|
[MIT](http://jryans.mit-license.org/)
|