Skip to content

Replace InternalCoroutinesApi with deprecation in NonCancellable #2765

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

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions kotlinx-coroutines-core/common/src/NonCancellable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,45 @@ import kotlin.coroutines.*
* when the parent is cancelled, the whole parent-child relation between parent and child is severed.
* The parent will not wait for the child's completion, nor will be cancelled when the child crashed.
*/
@Suppress("DeprecatedCallableAddReplaceWith")
public object NonCancellable : AbstractCoroutineContextElement(Job), Job {

private const val message = "NonCancellable can be used only as an argument for 'withContext', direct usages of its API are prohibited"

/**
* Always returns `true`.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
override val isActive: Boolean get() = true
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override val isActive: Boolean
get() = true

/**
* Always returns `false`.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override val isCompleted: Boolean get() = false

/**
* Always returns `false`.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override val isCancelled: Boolean get() = false

/**
* Always returns `false`.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun start(): Boolean = false

/**
* Always throws [UnsupportedOperationException].
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override suspend fun join() {
throw UnsupportedOperationException("This job is always active")
}
Expand All @@ -66,37 +71,37 @@ public object NonCancellable : AbstractCoroutineContextElement(Job), Job {
* Always throws [UnsupportedOperationException].
* @suppress **This an internal API and should not be used from general code.**
*/
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override val onJoin: SelectClause0
get() = throw UnsupportedOperationException("This job is always active")

/**
* Always throws [IllegalStateException].
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun getCancellationException(): CancellationException = throw IllegalStateException("This job is always active")

/**
* @suppress **This an internal API and should not be used from general code.**
*/
@Suppress("OverridingDeprecatedMember")
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle =
NonDisposableHandle

/**
* Always returns no-op handle.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun invokeOnCompletion(onCancelling: Boolean, invokeImmediately: Boolean, handler: CompletionHandler): DisposableHandle =
NonDisposableHandle

/**
* Does nothing.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun cancel(cause: CancellationException?) {}

/**
Expand All @@ -110,15 +115,15 @@ public object NonCancellable : AbstractCoroutineContextElement(Job), Job {
* Always returns [emptySequence].
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override val children: Sequence<Job>
get() = emptySequence()

/**
* Always returns [NonDisposableHandle] and does not do anything.
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
@Deprecated(level = DeprecationLevel.WARNING, message = message)
override fun attachChild(child: ChildJob): ChildHandle = NonDisposableHandle

/** @suppress */
Expand Down