Skip to content

Commit

Permalink
Remove redundant instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolan Murvihill authored and Dolan Murvihill committed Mar 10, 2024
1 parent 4350d80 commit 285229f
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/Semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ class Semaphore implements SemaphoreInterface {
if (i === -1 && weight <= this._value) {
// Needs immediate dispatch, skip the queue
this._dispatchItem(task);
} else if (i === -1) {
this._queue.splice(0, 0, task);
} else {
this._queue.splice(i + 1, 0, task);
}
this._dispatchQueue();
});
}

Expand All @@ -58,7 +55,6 @@ class Semaphore implements SemaphoreInterface {
return new Promise((resolve) => {
if (!this._weightedWaiters[weight - 1]) this._weightedWaiters[weight - 1] = [];
insertSorted(this._weightedWaiters[weight - 1], { resolve, priority });
this._dispatchQueue();
});
}
}
Expand Down Expand Up @@ -144,11 +140,7 @@ class Semaphore implements SemaphoreInterface {

function insertSorted<T extends Priority>(a: T[], v: T) {
const i = findIndexFromEnd(a, (other) => v.priority <= other.priority);
if (i === -1) {
a.splice(0, 0, v);
} else {
a.splice(i + 1, 0, v);
}
a.splice(i + 1, 0, v);
}

function findIndexFromEnd<T>(a: T[], predicate: (e: T) => boolean): number {
Expand Down

0 comments on commit 285229f

Please sign in to comment.