UNPKG

1.26 kBJavaScriptView Raw
1'use strict';
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10const getProfile = require('./profile').getProfile;
11const retry = require('promise-retry');
12function getRetryOptions() {
13 return __awaiter(this, void 0, void 0, function* () {
14 const profile = yield getProfile();
15 const retryOptions = {
16 retries: profile.retries,
17 factor: 2,
18 minTimeout: 1 * 1000,
19 randomize: true
20 };
21 return retryOptions;
22 });
23}
24function promiseRetry(fn) {
25 return __awaiter(this, void 0, void 0, function* () {
26 const retryOptions = yield getRetryOptions();
27 return retry(fn, retryOptions);
28 });
29}
30module.exports = promiseRetry;