You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,24 +15,27 @@ npm install set-timer
15
15
16
16
The `set-timer` function takes a callback function and an options object as arguments. The options are:
17
17
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).
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.
21
21
22
22
```javascript
23
23
var setTimer =require('set-timer');
24
24
25
+
// Prints "1", "2", "3", ..., "10", "I've been cleared!"
25
26
var timer =setTimer(function () {
26
-
// Prints 1, 2, 3, ...
27
27
console.log(this.calls);
28
28
}, {
29
-
timeout:5000, // Wait 5 seconds before first call.
30
-
interval:1000, // Wait 1 second between calls.
31
-
limit:Infinity// Keep calling indefinitely.
29
+
timeout:5000, // Wait 5 seconds before first call.
30
+
interval:1000, // Wait 1 second between calls.
31
+
limit:10, // Call callback 10 times.
32
+
onClear:function () { // Print after timer is cleared.
33
+
console.log("I've been cleared!");
34
+
}
32
35
});
33
36
```
34
37
35
-
You can clear the timer with`this.clear()` from inside of scope the callback, or `timer.clear()` in any scope that the timer has been defined.
38
+
Timers are automatically cleared after their call count reaches `options.limit`, but you can clear the timer manually`this.clear()` from inside of scope the callback or `timer.clear()` in the scope of the timer.
0 commit comments