From 4350d809276d7f85281c13e58706586f34e3f84b Mon Sep 17 00:00:00 2001 From: Dolan Murvihill Date: Thu, 1 Feb 2024 21:35:43 -0800 Subject: [PATCH] Reverse findIndex for queuing tasks in waitForUnlock() --- src/Semaphore.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semaphore.ts b/src/Semaphore.ts index 21f756c..aad9ce9 100644 --- a/src/Semaphore.ts +++ b/src/Semaphore.ts @@ -143,11 +143,11 @@ class Semaphore implements SemaphoreInterface { } function insertSorted(a: T[], v: T) { - const i = a.findIndex((other) => v.priority > other.priority); + const i = findIndexFromEnd(a, (other) => v.priority <= other.priority); if (i === -1) { - a.push(v); + a.splice(0, 0, v); } else { - a.splice(i, 0, v); + a.splice(i + 1, 0, v); } }