Skip to content

Commit c8eb15c

Browse files
committed
Complete promise outside lock.
1 parent 65e92d5 commit c8eb15c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/shared/common/src/main/java/com/launchdarkly/sdk/collections/IterableAsyncQueue.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ class IterableAsyncQueue<T> {
3737
* @param item the item to add (maybe null)
3838
*/
3939
public void put(T item) {
40+
CompletableFuture<T> pendingFuture = null;
4041
synchronized (lock) {
4142
CompletableFuture<T> nextFuture = pendingFutures.pollFirst();
4243
if(nextFuture != null) {
43-
nextFuture.complete(item);
44+
pendingFuture = nextFuture;
45+
} else {
46+
queue.addLast(item);
4447
return;
4548
}
46-
queue.addLast(item);
4749
}
50+
// Execute callback outside the lock.
51+
pendingFuture.complete(item);
4852
}
4953
/**
5054
* Retrieves and removes an item from the queue, returning a future that completes with the item.

0 commit comments

Comments
 (0)