-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathreadme.js
More file actions
executable file
·31 lines (24 loc) · 846 Bytes
/
readme.js
File metadata and controls
executable file
·31 lines (24 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
var backoff = require('../index.js');
var fibonacciBackoff = backoff.fibonacci({
randomisationFactor: 0,
initialDelay: 10,
maxDelay: 300
});
fibonacciBackoff.failAfter(10);
fibonacciBackoff.on('backoff', function(number, delay) {
// Do something when backoff starts, e.g. show to the
// user the delay before next reconnection attempt.
console.log(number + ' ' + delay + 'ms');
});
fibonacciBackoff.on('ready', function(number, delay) {
// Do something when backoff ends, e.g. retry a failed
// operation (DNS lookup, API call, etc.).
fibonacciBackoff.backoff();
});
fibonacciBackoff.on('fail', function() {
// Do something when the maximum number of backoffs is
// reached, e.g. ask the user to check its connection.
console.log('fail');
});
fibonacciBackoff.backoff();