about summary refs log tree commit diff
path: root/src/lib/async
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-03-15 15:05:13 -0500
committerGitHub <noreply@github.com>2023-03-15 15:05:13 -0500
commit3c05a08482cbcff452ece8c11ff3a2a740c79503 (patch)
treeda6458cb8238b1537372c66ffb63d46d9f2ecae6 /src/lib/async
parent94741cddedaa9c923f37b7cc11d5a2cbab81ca44 (diff)
downloadvoidsky-3c05a08482cbcff452ece8c11ff3a2a740c79503.tar.zst
Logout bug hunt (#294)
* Stop storing the log on disk

* Add more info to the session logging

* Only clear session tokens from storage when they've expired

* Retry session resumption a few times if it's a network issue

* Improvements to the 'connecting' screen
Diffstat (limited to 'src/lib/async')
-rw-r--r--src/lib/async/retry.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/async/retry.ts b/src/lib/async/retry.ts
new file mode 100644
index 000000000..f14ae6cf6
--- /dev/null
+++ b/src/lib/async/retry.ts
@@ -0,0 +1,29 @@
+import {isNetworkError} from 'lib/strings/errors'
+
+export async function retry<P>(
+  retries: number,
+  cond: (err: any) => boolean,
+  fn: () => Promise<P>,
+): Promise<P> {
+  let lastErr
+  while (retries > 0) {
+    try {
+      return await fn()
+    } catch (e: any) {
+      lastErr = e
+      if (cond(e)) {
+        retries--
+        continue
+      }
+      throw e
+    }
+  }
+  throw lastErr
+}
+
+export async function networkRetry<P>(
+  retries: number,
+  fn: () => Promise<P>,
+): Promise<P> {
+  return retry(retries, isNetworkError, fn)
+}