Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
fix binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Sep 7, 2020
1 parent 9b5bbf8 commit 8f0df5d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/prioritizedTaskExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class PrioritizedTaskExecutor {
fn(async () => {
self.currentPoolSize--
if (self.queue.length > 0) {
await self.lock.acquire()
const item = self.queue.shift()
await self.lock.signal()
await self.execute(item!.priority, item!.fn)
}
})
Expand Down Expand Up @@ -80,11 +82,18 @@ export class PrioritizedTaskExecutor {
}
break
}

if (value > priority) {
left = index
left = index + 1
} else {
right = index
right = index - 1
}
if (left > right) {
if (this.currentPoolSize < this.maxPoolSize) {
runTask()
} else {
this.queue.splice(left, 0, { priority, fn })
}
break
}
}
}
Expand Down

0 comments on commit 8f0df5d

Please sign in to comment.