Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint warnings on SharedFlow operations that never complete #2376

Merged
merged 2 commits into from Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.",
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
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()