Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/retry.js
3520 views
1
"use strict";
2
Object.defineProperty(exports, "__esModule", { value: true });
3
exports.retry = retry;
4
/*---------------------------------------------------------------------------------------------
5
* Copyright (c) Microsoft Corporation. All rights reserved.
6
* Licensed under the MIT License. See License.txt in the project root for license information.
7
*--------------------------------------------------------------------------------------------*/
8
async function retry(fn) {
9
let lastError;
10
for (let run = 1; run <= 10; run++) {
11
try {
12
return await fn(run);
13
}
14
catch (err) {
15
if (!/fetch failed|terminated|aborted|timeout|TimeoutError|Timeout Error|RestError|Client network socket disconnected|socket hang up|ECONNRESET|CredentialUnavailableError|endpoints_resolution_error|Audience validation failed|end of central directory record signature not found/i.test(err.message)) {
16
throw err;
17
}
18
lastError = err;
19
// maximum delay is 10th retry: ~3 seconds
20
const millis = Math.floor((Math.random() * 200) + (50 * Math.pow(1.5, run)));
21
await new Promise(c => setTimeout(c, millis));
22
}
23
}
24
console.error(`Too many retries, aborting.`);
25
throw lastError;
26
}
27
//# sourceMappingURL=retry.js.map
28