-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.js
95 lines (76 loc) · 3.19 KB
/
examples.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict;'
const bluebird = require('bluebird');
const bluebirdretryjs = require('./bluebird.retry');
var resolves_ok = bluebird.resolve('resolved');
var resolves_rejected = bluebird.reject('rejected');
var fn_ok = () => { return "success" };
var fn_throws = () => { throw new Error("rejected"); };
const RetryAttemptsExceeded = bluebirdretryjs.exceptions.RetryAttemptsExceeded;
const PredicateViolation = bluebirdretryjs.exceptions.PredicateViolation;
bluebirdretryjs.retry(resolves_ok)
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error(err.message);
});
bluebirdretryjs.retry(fn_ok)
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error(err.message);
});
bluebirdretryjs.predicatedRetry(bluebird.resolve('predicate example success'), (retryAttemptIndex) => retryAttemptIndex >= 1)
.then((result) => console.log(result))
bluebirdretryjs.predicatedRetry(bluebird.reject('predicate example rejection'), (retryAttemptIndex) => retryAttemptIndex >= 1)
.then((result) => console.log(result))
.catch(PredicateViolation, (err) => {
console.error(err.message);
});
bluebirdretryjs.retry(resolves_rejected)
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Default: " + err.message);
});
bluebirdretryjs.retry(resolves_rejected, 4, bluebirdretryjs.backoff.constant(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Constant: " + err.message);
});
bluebirdretryjs.retry(resolves_rejected, 4, bluebirdretryjs.backoff.linear(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Linear: " + err.message);
});
bluebirdretryjs.retry(resolves_rejected, 4, bluebirdretryjs.backoff.quadratic(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Quadratic: " + err.message);
});
bluebirdretryjs.retry(resolves_rejected, 4, bluebirdretryjs.backoff.exponential(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Exponential: " + err.message);
});
bluebirdretryjs.retry(fn_throws)
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Default: " + err.message);
});
bluebirdretryjs.retry(fn_throws, 4, bluebirdretryjs.backoff.constant(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Constant: " + err.message);
});
bluebirdretryjs.retry(fn_throws, 4, bluebirdretryjs.backoff.linear(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Linear: " + err.message);
});
bluebirdretryjs.retry(fn_throws, 4, bluebirdretryjs.backoff.quadratic(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Quadratic: " + err.message);
});
bluebirdretryjs.retry(fn_throws, 4, bluebirdretryjs.backoff.exponential(1))
.then((result) => console.log(result))
.catch(RetryAttemptsExceeded, (err) => {
console.error("Exponential: " + err.message);
});