-
Notifications
You must be signed in to change notification settings - Fork 1
/
resolute-test.js
34 lines (28 loc) · 1.04 KB
/
resolute-test.js
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
32
33
34
var Resolute = require("./resolute");
var somePromiseOperation = function() {
return new Promise(function(resolve, reject) {
// Make it fail...
if (err) return reject(err);
resolve("success");
});
};
var resolute_options = {
// Reference to your Promise function, note: this Promise will always fail.
operation: somePromiseOperation,
// Maximum number of times to attempt
maxRetry: 5,
// Delay between retries in milliseconds
delay: 2000
};
var resolute_callback = function(retryCount) {
console.log(retryCount);
};
var resolute = new Resolute(resolute_options, resolute_callback);
// Run the operation stored in options.
resolute.run().then(null).catch(function(err) {
console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});
// Pass in a new operation to perform using the same Resolute instance.
resolute.run(somePromiseOperation).then(null).catch(function(err) {
console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});