Improve feed loader, wait for db before executing reads/updates, make taskQueue subscribable, add race, rename auth methods, fix failed wasm verify, fix localhost urls

This commit is contained in:
Jon Staab
2025-04-09 15:39:07 -07:00
parent 1bcc57d695
commit 859f7fa68f
14 changed files with 155 additions and 32 deletions
+26
View File
@@ -1038,6 +1038,32 @@ export const batcher = <T, U>(t: number, execute: (request: T[]) => U[] | Promis
})
}
/**
* Returns a promise that resolves after some proportion of promises complete
* @param threshold - number between 0 and 1 for how many promises to wait for
* @param promises - array of promises
* @returns promise
*/
export const race = (threshold: number, promises: Promise<unknown>[]) => {
let count = 0
if (threshold === 0) {
return Promise.resolve()
}
return new Promise<void>((resolve, reject) => {
promises.forEach(p => {
p.then(() => {
count++
if (count >= threshold * promises.length) {
resolve()
}
}).catch(reject)
})
})
}
// ----------------------------------------------------------------------------
// URLs
// ----------------------------------------------------------------------------