You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-10 09:22:25 +03:00
Retry joinRoom up to 5 times in the case of a 504 GATEWAY TIMEOUT
This commit is contained in:
@@ -68,3 +68,21 @@ export function allSettled<T>(promises: Promise<T>[]): Promise<Array<ISettledFul
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
// Helper method to retry a Promise a given number of times or until a predicate fails
|
||||
export async function retry<T, E extends Error>(fn: () => Promise<T>, num: number, predicate?: (e: E) => boolean) {
|
||||
let lastErr: E;
|
||||
for (let i = 0; i < num; i++) {
|
||||
try {
|
||||
const v = await fn();
|
||||
// If `await fn()` throws then we won't reach here
|
||||
return v;
|
||||
} catch (err) {
|
||||
if (predicate && !predicate(err)) {
|
||||
throw err;
|
||||
}
|
||||
lastErr = err;
|
||||
}
|
||||
}
|
||||
throw lastErr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user