diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-04-09 01:10:28 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-04-22 00:52:22 -0400 |
| commit | 40b91af8007dd0a5d180eba37a8168ca12e013e2 (patch) | |
| tree | 6c3c681cd5dc722b707b50b09fb46a2ec1e3bfaf /ui/lib/retry.js | |
| parent | 1ef57107b1c355ef896327f0714344277df7ae18 (diff) | |
When booting a session, retry every five seconds if unable to send the request.
This is intended to transparently resume the session (using `boot` to start over) after more serious connection interruptions. It interacts with the heartbeat timeout: we let the browser try to reconnect through `EventSource` on its own for up to 30 seconds, before intervening, closing the event source, and starting attempts to call `boot`.
This covers both initial boot, which will now hang if the server is unavailable (sorry), and reconnection after an event timeout. No other operations are retried (particularly, sending a message is _not_ retried).
Diffstat (limited to 'ui/lib/retry.js')
| -rw-r--r-- | ui/lib/retry.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ui/lib/retry.js b/ui/lib/retry.js new file mode 100644 index 0000000..777f1be --- /dev/null +++ b/ui/lib/retry.js @@ -0,0 +1,21 @@ +export async function retry(callback, retryCond, delay) { + while (true) { + try { + return await callback(); + } catch (err) { + if (retryCond(err)) { + await delay(); + } else { + throw err; + } + } + } +} + +export function delay(millis) { + return async () => await sleep(millis); +} + +function sleep(millis) { + return new Promise((resolve) => setTimeout(resolve, millis)); +} |
