Skip to content

Commit f852554

Browse files
committed
Get rid of changes in the public API
1 parent db906d8 commit f852554

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

IntelliJ-patches.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ Some logic related to instrumentation was extracted to separate methods so that
7777
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.emitInternal(FlowCollector, value)` -- alternative of a regular `FlowCollector.emit` that supports insertion points; if there is a `FlowCollector`, its `emit` call can be replaced with `emitInternal` so this case would also be supported for constructing async stack traces
7878
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.debuggerCapture` -- common insertion point for a debugger agent; simplifies instrumentation; the value is always being unwrapped inside. `emitInternal` uses this method.
7979

80+
One internal method was added to `BufferedChannel`: `emitAllInternal`. This method ensures the value will be unwrapped in an insertion point.
81+
8082
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.
8183

8284
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.
8385

84-
One public method was added to support `buffer` and operators that use it inside:
85-
- `ReceiveChannel.emitAll`. It encapsulates emitting values in `FlowCollector.emitAllImpl` and has a special implementation in `BufferedChannel`.
86-
8786
Changes were made to lambda parameter `onElementRetrieved` in `BufferedChannel<E>` methods: now they accept `Any?` instead of `E` because now they may be given a wrapped value.
8887

8988
`SelectImplementation.complete` now uses `debuggerCapture` to properly propagate value that might come from flows.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ internal open class BufferedChannel<E>(
15521552

15531553
override fun iterator(): ChannelIterator<E> = BufferedChannelIterator()
15541554

1555-
override suspend fun emitAll(collector: FlowCollector<E>) {
1555+
internal suspend fun emitAllInternal(collector: FlowCollector<E>) {
15561556
val iterator = iterator() as BufferedChannel.BufferedChannelIterator
15571557
while (iterator.hasNext()) {
15581558
collector.emitInternal(iterator.nextInternal())

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,6 @@ public interface ReceiveChannel<out E> {
289289
*/
290290
public operator fun iterator(): ChannelIterator<E>
291291

292-
/**
293-
* Emits all elements of this channel using [collector].
294-
*/
295-
public suspend fun emitAll(collector: FlowCollector<E>) {
296-
for (element in this) {
297-
collector.emit(element)
298-
}
299-
}
300-
301292
/**
302293
* Cancels reception of remaining elements from this channel with an optional [cause].
303294
* This function closes the channel and removes all buffered sent elements from it.

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

Lines changed: 14 additions & 1 deletion
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-
channel.emitAll(this)
32+
emitAll(channel, this)
3333
} catch (e: Throwable) {
3434
cause = e
3535
throw e
@@ -38,6 +38,19 @@ 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>) {
42+
when (channel) {
43+
is BufferedChannel<*> -> {
44+
(channel as BufferedChannel<T>).emitAllInternal(collector)
45+
}
46+
else -> {
47+
for (element in channel) {
48+
collector.emit(element)
49+
}
50+
}
51+
}
52+
}
53+
4154
/**
4255
* Represents the given receive channel as a hot flow and [receives][ReceiveChannel.receive] from the channel
4356
* in fan-out fashion every time this flow is collected. One element will be emitted to one collector only.

0 commit comments

Comments
 (0)