Skip to content

Commit

Permalink
perf(providers): re-check the event queue while holding the lock in `…
Browse files Browse the repository at this point in the history
…BlockingSubscriptionStream`

this avoids awaiting in case the condition signal was missed
  • Loading branch information
ArtificialPB committed Dec 14, 2024
1 parent 4bb517e commit e65d393
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ class BlockingSubscriptionStream<T> private constructor(

// if no next element, wait until next event to avoid CPU cycle burning
if (next == null) {
lock.withLock { newEventCondition.await() }
lock.withLock {
// re-check the queue, as it might have been modified by the time we got the lock, and the
// signalling of the condition might have been missed
next = eventQueue.poll()

if (next == null) {
newEventCondition.await()
}
}
}
}

Expand Down

0 comments on commit e65d393

Please sign in to comment.