@@ -13,22 +13,32 @@ npm install set-timer
1313
1414## Usage
1515
16- The ` setTimer ` function takes a callback function and an options object as arguments. The options are:
16+ The ` setTimer ` function takes a callback function and an optional options object as arguments.
1717
18- * ** Timeout:** Number of milliseconds to wait before the first call, default 0.
19- * ** Interval:** Number of milliseconds to wait between calls, default 0.
20- * ** Limit:** Number of times to call callback, default 1. Use ` Infinity ` to call indefinitely.
18+ ``` javascript
19+ var setTimer = require (' set-timer' );
20+
21+ setTimer (function () {
22+ console .log (" I'm called immediately!" );
23+ });
24+ ```
25+
26+ The options are:
27+
28+ * ** Timeout:** Number of milliseconds to wait before the first call (default: ` 0 ` ).
29+ * ** Limit:** Number of times to call callback (default: ` 1 ` ). Use ` Infinity ` to call indefinitely.
30+ * ** Interval:** Number of milliseconds to wait between calls (default: ` 0 ` ). Ignored unless ` limit > 1 ` .
31+ * ** onClear:** Function to call after timer has been cleared (default: ` Function.prototype ` ).
2132
2233``` javascript
2334var setTimer = require (' set-timer' );
2435
25- // Prints "1", "2", "3", ..., "10", "Cleared!"
2636var timer = setTimer (function () {
27- console .log (this .calls );
37+ console .log (" I've been called " + this .calls + " times! " );
2838}, {
2939 timeout: 5000 , // Wait 5 seconds before first call.
30- interval: 1000 , // Wait 1 second between calls.
3140 limit: 10 , // Call callback 10 times.
41+ interval: 1000 , // Wait 1 second between calls.
3242 onClear : function () { // Call after timer is cleared.
3343 console .log (" Cleared!" );
3444 }
0 commit comments