1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

move fn to http-api and add jsdoc

This commit is contained in:
Bruno Windels
2020-04-23 15:32:40 +02:00
parent 86913dccb0
commit 6b4fefc123
3 changed files with 37 additions and 25 deletions

View File

@@ -749,26 +749,3 @@ export function setCrypto(c: Object) {
export function getCrypto(): Object {
return crypto;
}
export async function retryNetworkOperation(maxAttempts, callback) {
let attempts = 0;
let lastConnectionError = null;
while (attempts < maxAttempts) {
try {
if (attempts > 0) {
const timeout = 1000 * Math.pow(2, attempts);
console.log(`network operation failed ${attempts} times, retrying in ${timeout}ms...`);
await new Promise(r => setTimeout(r, timeout));
}
return await callback();
} catch (err) {
if (err instanceof ConnectionError) {
attempts += 1;
lastConnectionError = err;
} else {
throw err;
}
}
}
throw lastConnectionError;
}