Update src/index.ts

Co-authored-by: Shigma <shigma10826@gmail.com>
This commit is contained in:
Maiko Sinkyaet Tan 2024-08-16 00:43:09 +08:00 committed by GitHub
parent a6bd059670
commit 7b2aa62fbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -309,9 +309,11 @@ export function apply(ctx: Context, config: Config) {
if (globalTasks.size >= config.globalConcurrency) {
const pendingId = container.pop()
globalPending.add(pendingId)
await new Promise<void>((resolve) => ctx.once('novelai/finish', (id) => {
if (id === pendingId) {
await new Promise<void>((resolve) => {
const dispose = ctx.on('novelai/finish', (id) => {
if (id !== pendingId) return
resolve()
dispose()
}
}))
}