Skip to content

Commit

Permalink
Add lint warnings on SharedFlow operations that never complete (#2376)
Browse files Browse the repository at this point in the history
* Add lint warnings on SharedFlow operations that never complete

Fixes #2340
Fixes #2368

* ~ remove awaitCancellation replacements
  • Loading branch information
elizarov committed Nov 17, 2020
1 parent bc553ba commit 598b861
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions kotlinx-coroutines-core/common/src/flow/operators/Lint.kt
Expand Up @@ -2,12 +2,13 @@
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("unused")
@file:Suppress("unused", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")

package kotlinx.coroutines.flow

import kotlinx.coroutines.*
import kotlin.coroutines.*
import kotlin.internal.InlineOnly

/**
* Applying [cancellable][Flow.cancellable] to a [SharedFlow] has no effect.
Expand Down Expand Up @@ -79,4 +80,61 @@ public fun FlowCollector<*>.cancel(cause: CancellationException? = null): Unit =
replaceWith = ReplaceWith("currentCoroutineContext()")
)
public val FlowCollector<*>.coroutineContext: CoroutineContext
get() = noImpl()
get() = noImpl()

@Deprecated(
message = "SharedFlow never completes, so this operator has no effect.",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("this")
)
@InlineOnly
public inline fun <T> SharedFlow<T>.catch(noinline action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T> =
(this as Flow<T>).catch(action)

@Deprecated(
message = "SharedFlow never completes, so this operator has no effect.",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("this")
)
@InlineOnly
public inline fun <T> SharedFlow<T>.retry(
retries: Long = Long.MAX_VALUE,
noinline predicate: suspend (cause: Throwable) -> Boolean = { true }
): Flow<T> =
(this as Flow<T>).retry(retries, predicate)

@Deprecated(
message = "SharedFlow never completes, so this operator has no effect.",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("this")
)
@InlineOnly
public inline fun <T> SharedFlow<T>.retryWhen(noinline predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T> =
(this as Flow<T>).retryWhen(predicate)

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
message = "SharedFlow never completes, so this terminal operation never completes.",
level = DeprecationLevel.WARNING
)
@InlineOnly
public suspend inline fun <T> SharedFlow<T>.toList(): List<T> =
(this as Flow<T>).toList()

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
message = "SharedFlow never completes, so this terminal operation never completes.",
level = DeprecationLevel.WARNING
)
@InlineOnly
public suspend inline fun <T> SharedFlow<T>.toSet(): Set<T> =
(this as Flow<T>).toSet()

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
message = "SharedFlow never completes, so this terminal operation never completes.",
level = DeprecationLevel.WARNING
)
@InlineOnly
public suspend inline fun <T> SharedFlow<T>.count(): Int =
(this as Flow<T>).count()

0 comments on commit 598b861

Please sign in to comment.