Skip to content

Commit 4a2ad89

Browse files
committed
Fixed ArrayBroadcastChannel receive of stale elements on openSubscription
1 parent 45c8565 commit 4a2ad89

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/ArrayBroadcastChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ArrayBroadcastChannel<E>(
7272

7373
override fun openSubscription(): SubscriptionReceiveChannel<E> {
7474
bufferLock.withLock {
75-
val sub = Subscriber(this, head)
75+
val sub = Subscriber(this, tail)
7676
subs.add(sub)
7777
return sub
7878
}

core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/BroadcastChannelSubStressTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class BroadcastChannelSubStressTest(
6161
broadcast.openSubscription().use { sub ->
6262
val i = sub.receive()
6363
check(i >= last) { "Last was $last, got $i" }
64+
if (!kind.isConflated) check(i != last) { "Last was $last, got it again" }
6465
receivedTotal.incrementAndGet()
6566
last = i
6667
}

0 commit comments

Comments
 (0)