-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.js
32 lines (26 loc) · 902 Bytes
/
configure.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
'use strict';
const assert = require('assert');
module.exports = function configure(arg, current) {
if (arg.retries) {
if (arg.attempts) {
throw new Error('Specify attempts or retries, but not both');
}
arg.attempts = arg.retries + 1;
delete arg.retries;
}
const {
attempts = current.attempts,
backoff = current.backoff,
condition = current.condition,
timeout = current.timeout,
} = arg;
assert(Number.isInteger(attempts) && attempts > 0, 'attempts must be an integer > 0');
assert(typeof backoff === 'function', 'backoff must be a function');
assert(typeof condition === 'function', 'condition must be a function')
assert(timeout === undefined || Number.isInteger(timeout), 'timeout, if specified, must be a number');
arg.attempts = attempts;
arg.backoff = backoff;
arg.condition = condition;
arg.timeout = timeout;
return arg;
};