Skip to content

Commit

Permalink
Get rid of @InternalCoroutinesApi from Flow.collect member (#3082)
Browse files Browse the repository at this point in the history
* Get rid of @InternalCoroutinesApi from Flow.collect member

Fixes #3078
  • Loading branch information
qwwdfsad committed Dec 14, 2021
1 parent d220071 commit 48aa354
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 6 deletions.
1 change: 0 additions & 1 deletion integration/kotlinx-coroutines-jdk8/src/stream/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public fun <T> Stream<T>.consumeAsFlow(): Flow<T> = StreamFlow(this)
private class StreamFlow<T>(private val stream: Stream<T>) : Flow<T> {
private val consumed = atomic(false)

@InternalCoroutinesApi
override suspend fun collect(collector: FlowCollector<T>) {
if (!consumed.compareAndSet(false, true)) error("Stream.consumeAsFlow can be collected only once")
try {
Expand Down
4 changes: 1 addition & 3 deletions kotlinx-coroutines-core/common/src/flow/Flow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ import kotlin.coroutines.*
*
* **The `Flow` interface is not stable for inheritance in 3rd party libraries**, as new methods
* might be added to this interface in the future, but is stable for use.
* Use the `flow { ... }` builder function to create an implementation.
* Use the `flow { ... }` builder function to create an implementation, or extend [AbstractFlow].
*/
public interface Flow<out T> {
/**
Expand All @@ -184,7 +184,6 @@ public interface Flow<out T> {
* should be used. Such limitation ensures that the context preservation property is not violated and prevents most

This comment was marked as outdated.

Copy link
@alexvanyo

alexvanyo Dec 14, 2021

Contributor

This method should never be implemented or used directly

or collect { ... } extension should be used.

#3078
Could the documentation be updated to be more clear that this is the intended way to collect a Flow now?

* of the developer mistakes related to concurrency, inconsistent flow dispatchers and cancellation.
*/
@InternalCoroutinesApi
public suspend fun collect(collector: FlowCollector<T>)
}

Expand Down Expand Up @@ -214,7 +213,6 @@ public interface Flow<out T> {
@FlowPreview
public abstract class AbstractFlow<T> : Flow<T>, CancellableFlow<T> {

@InternalCoroutinesApi
public final override suspend fun collect(collector: FlowCollector<T>) {
val safeCollector = SafeCollector(collector, coroutineContext)
try {
Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/common/src/flow/SharedFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public interface SharedFlow<out T> : Flow<T> {
*
* @see [Flow.collect]
*/
@InternalCoroutinesApi
override suspend fun collect(collector: FlowCollector<T>): Nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private class DistinctFlowImpl<T>(
@JvmField val keySelector: (T) -> Any?,
@JvmField val areEquivalent: (old: Any?, new: Any?) -> Boolean
): Flow<T> {
@InternalCoroutinesApi
override suspend fun collect(collector: FlowCollector<T>) {
var previousKey: Any? = NULL
upstream.collect { value ->
Expand Down

0 comments on commit 48aa354

Please sign in to comment.