Skip to content

Commit 9836a6b

Browse files
committed
Get rid of changes in the public API -- bring back CoroutineChannel support
1 parent f852554 commit 9836a6b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

IntelliJ-patches.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Some logic related to instrumentation was extracted to separate methods so that
7979

8080
One internal method was added to `BufferedChannel`: `emitAllInternal`. This method ensures the value will be unwrapped in an insertion point.
8181

82+
One internal method was added to `flow/Channels.kt`: `emitAllInternal`. It emits all values, like usual, but also considers wrapping/unwrapping supported in `BufferedChannel`.
83+
84+
One internal method was added to `ChannelCoroutine`: `emitAllInternal` serves to bridge its delegate and the method above.
85+
8286
One internal method was added to `BufferedChannelIterator`: `nextInternal` -- same as `next` but may return a wrapped value. It should only be used with a function that is capable of unwrapping the value (see `BufferedChannel.emitAll` and `BufferedChannelIterator.next`), so there's a guarantee a wrapped value will always unwrap before emitting.
8387

8488
Why not just let `next` return a maybe wrapped value? That's because it is heavily used outside a currently supported scope. For example, one may just indirectly call it from a for-loop. In this case, unwrapping will never happen, and a user will get a handful of `ClassCastException`s.

kotlinx-coroutines-core/common/src/channels/ChannelCoroutine.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package kotlinx.coroutines.channels
22

33
import kotlinx.coroutines.*
4+
import kotlinx.coroutines.flow.FlowCollector
5+
import kotlinx.coroutines.flow.emitAllInternal
46
import kotlin.coroutines.*
57

68
internal open class ChannelCoroutine<E>(
@@ -35,4 +37,8 @@ internal open class ChannelCoroutine<E>(
3537
_channel.cancel(exception) // cancel the channel
3638
cancelCoroutine(exception) // cancel the job
3739
}
40+
41+
internal suspend fun emitAllInternal(flowCollector: FlowCollector<E>) {
42+
emitAllInternal(_channel, flowCollector)
43+
}
3844
}

kotlinx-coroutines-core/common/src/flow/Channels.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>,
2929
ensureActive()
3030
var cause: Throwable? = null
3131
try {
32-
emitAll(channel, this)
32+
emitAllInternal(channel, this)
3333
} catch (e: Throwable) {
3434
cause = e
3535
throw e
@@ -38,11 +38,14 @@ private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>,
3838
}
3939
}
4040

41-
private suspend fun <T> emitAll(channel: ReceiveChannel<T>, collector: FlowCollector<T>) {
41+
internal suspend fun <T> emitAllInternal(channel: ReceiveChannel<T>, collector: FlowCollector<T>) {
4242
when (channel) {
4343
is BufferedChannel<*> -> {
4444
(channel as BufferedChannel<T>).emitAllInternal(collector)
4545
}
46+
is ChannelCoroutine<*> -> {
47+
(channel as ChannelCoroutine<T>).emitAllInternal(collector)
48+
}
4649
else -> {
4750
for (element in channel) {
4851
collector.emit(element)

0 commit comments

Comments
 (0)