* new settings screen * bring back the spinner * add experimental language * fix typo, change leading * integrate priority notifications API * update package * use refetch instead of invalidateQueries * fix read-after-write issue by polling for update * add spinner for initial load * rm onmutate, it's overcomplicated * set error state eagerly * Change language in description Co-authored-by: Hailey <me@haileyok.com> * prettier * add `Toggle.Platform` * extract out mutation hook + error state * rm useless cache mutation * disambiguate isError and isPending * rm unused isError --------- Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com> Co-authored-by: Hailey <me@haileyok.com>
26 lines
605 B
TypeScript
26 lines
605 B
TypeScript
import {timeout} from './timeout'
|
|
|
|
export async function until<T>(
|
|
retries: number,
|
|
delay: number,
|
|
cond: (v: T, err: any) => boolean,
|
|
fn: () => Promise<T>,
|
|
): Promise<boolean> {
|
|
while (retries > 0) {
|
|
try {
|
|
const v = await fn()
|
|
if (cond(v, undefined)) {
|
|
return true
|
|
}
|
|
} catch (e: any) {
|
|
// TODO: change the type signature of cond to accept undefined
|
|
// however this breaks every existing usage of until -sfn
|
|
if (cond(undefined as unknown as T, e)) {
|
|
return true
|
|
}
|
|
}
|
|
await timeout(delay)
|
|
retries--
|
|
}
|
|
return false
|
|
}
|