reorg again, absolute (module) imports

This commit is contained in:
austinried
2021-07-08 12:21:44 +09:00
parent a94a011a18
commit ea4421b7af
54 changed files with 186 additions and 251 deletions

31
app/util/PromiseQueue.ts Normal file
View File

@@ -0,0 +1,31 @@
type QueuedPromise = () => Promise<any>
class PromiseQueue {
maxSimultaneously: number
private active = 0
private queue: QueuedPromise[] = []
constructor(maxSimultaneously = 1) {
this.maxSimultaneously = maxSimultaneously
}
async enqueue<T>(func: () => Promise<T>) {
if (++this.active > this.maxSimultaneously) {
await new Promise(resolve => this.queue.push(resolve as QueuedPromise))
}
try {
return await func()
} catch (err) {
throw err
} finally {
this.active--
if (this.queue.length) {
this.queue.shift()?.()
}
}
}
}
export default PromiseQueue