mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
17 lines
425 B
TypeScript
17 lines
425 B
TypeScript
export function createRebuildQueue(build: () => void | Promise<void>): () => Promise<void> {
|
|
let pending = false
|
|
let active: Promise<void> | undefined
|
|
return () => {
|
|
pending = true
|
|
if (!active) {
|
|
active = Promise.resolve().then(async () => {
|
|
while (pending) {
|
|
pending = false
|
|
await build()
|
|
}
|
|
}).finally(() => { active = undefined })
|
|
}
|
|
return active
|
|
}
|
|
}
|