Skip to content

Commit

Permalink
Simplify grabJob logic
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka committed Aug 21, 2017
1 parent ffaa9c1 commit 826aafe
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/main/java/com/spotify/futures/ConcurrencyLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,16 @@ public int remainingActiveCapacity() {
* 2) return null and does not acquire a permit from the semaphore
*/
private Job<T> grabJob() {
while (!queue.isEmpty()) {
if (!limit.tryAcquire()) {
return null;
}

final Job<T> job = queue.poll();
if (job != null) {
return job;
}
if (!limit.tryAcquire()) {
return null;
}

limit.release();
final Job<T> job = queue.poll();
if (job != null) {
return job;
}

limit.release();
return null;
}

Expand Down

0 comments on commit 826aafe

Please sign in to comment.