5
5
package kotlinx.coroutines.channels
6
6
7
7
import kotlinx.coroutines.selects.*
8
- import kotlinx.coroutines.internal.*
9
8
10
9
/* *
11
10
* Channel that buffers at most one element and conflates all subsequent `send` and `offer` invocations,
@@ -24,31 +23,20 @@ internal open class ConflatedChannel<E> : AbstractChannel<E>() {
24
23
protected final override val isBufferAlwaysFull: Boolean get() = false
25
24
protected final override val isBufferFull: Boolean get() = false
26
25
27
- override fun onClosedIdempotent (closed : LockFreeLinkedListNode ) {
28
- conflatePreviousSendBuffered(closed)
29
- }
30
-
31
26
// result is always `OFFER_SUCCESS | Closed`
32
27
protected override fun offerInternal (element : E ): Any {
33
28
while (true ) {
34
29
val result = super .offerInternal(element)
35
30
when {
36
31
result == = OFFER_SUCCESS -> return OFFER_SUCCESS
37
32
result == = OFFER_FAILED -> { // try to buffer
38
- val sendResult = sendConflated(element)
39
- when (sendResult) {
33
+ when (val sendResult = sendConflated(element)) {
40
34
null -> return OFFER_SUCCESS
41
- is Closed <* > -> {
42
- conflatePreviousSendBuffered(sendResult)
43
- return sendResult
44
- }
35
+ is Closed <* > -> return sendResult
45
36
}
46
37
// otherwise there was receiver in queue, retry super.offerInternal
47
38
}
48
- result is Closed <* > -> {
49
- conflatePreviousSendBuffered(result)
50
- return result
51
- }
39
+ result is Closed <* > -> return result
52
40
else -> error(" Invalid offerInternal result $result " )
53
41
}
54
42
}
@@ -64,10 +52,7 @@ internal open class ConflatedChannel<E> : AbstractChannel<E>() {
64
52
result == = ALREADY_SELECTED -> return ALREADY_SELECTED
65
53
result == = OFFER_SUCCESS -> return OFFER_SUCCESS
66
54
result == = OFFER_FAILED -> {} // retry
67
- result is Closed <* > -> {
68
- conflatePreviousSendBuffered(result)
69
- return result
70
- }
55
+ result is Closed <* > -> return result
71
56
else -> error(" Invalid result $result " )
72
57
}
73
58
}
0 commit comments