Repository: Kotlin/kotlinx.coroutines
File: kotlinx-coroutines-core/common/src/CancellableContinuationImpl.kt (Kotlin)

Code before:
    public override fun toString(): String =
        "${nameString()}(${delegate.toDebugString()}){$stateDebugRepresentation}@$hexAddress"

    protected open fun nameString(): String =
        "CancellableContinuation"

}

// Marker for active continuation
internal interface NotCompleted

private object Active : NotCompleted {
    override fun toString(): String = "Active"
}

/**
 * Essentially the same as just a function from `Throwable?` to `Unit`.
 * The only thing implementors can do is call [invoke].
 * The reason this abstraction exists is to allow providing a readable [toString] in the list of completion handlers
 * as seen from the debugger.
 * Use [UserSupplied] to create an instance from a lambda.
 * We can't avoid defining a separate type, because on JS, you can't inherit from a function type.
 *
 * @see InternalCompletionHandler for a very similar interface, but used for handling completion and not cancellation.
 */
internal interface CancelHandler: NotCompleted {
    /**
     * Signal cancellation.
     *
     * This function:
     * - Does not throw any exceptions.
     *   Violating this rule in an implementation leads to [handleUncaughtCoroutineException] being called with a
     *   [CompletionHandlerException] wrapping the thrown exception.
     * - Is fast, non-blocking, and thread-safe.
     * - Can be invoked concurrently with the surrounding code.
     * - Can be invoked from any context.
     */
    fun invoke(cause: Throwable?)

    /**
     * A lambda passed from outside the coroutine machinery.
     *
     * See the requirements for [CancelHandler.invoke] when implementing this function.
     */
    class UserSupplied(private val handler: (cause: Throwable?) -> Unit) : CancelHandler {
        /** @suppress */
        override fun invoke(cause: Throwable?) { handler(cause) }

        override fun toString() = "CancelHandler.UserSupplied[${handler.classSimpleName}@$hexAddress]"
    }
}

Review comment (suggestion):
```suggestion
internal interface CancelHandler : NotCompleted {
```

Code after:
    public override fun toString(): String =
        "${nameString()}(${delegate.toDebugString()}){$stateDebugRepresentation}@$hexAddress"

    protected open fun nameString(): String =
        "CancellableContinuation"

}

// Marker for active continuation
internal interface NotCompleted

private object Active : NotCompleted {
    override fun toString(): String = "Active"
}

/**
 * Essentially the same as just a function from `Throwable?` to `Unit`.
 * The only thing implementors can do is call [invoke].
 * The reason this abstraction exists is to allow providing a readable [toString] in the list of completion handlers
 * as seen from the debugger.
 * Use [UserSupplied] to create an instance from a lambda.
 * We can't avoid defining a separate type, because on JS, you can't inherit from a function type.
 *
 * @see InternalCompletionHandler for a very similar interface, but used for handling completion and not cancellation.
 */
internal interface CancelHandler : NotCompleted {
    /**
     * Signals cancellation.
     *
     * This function:
     * - Does not throw any exceptions.
     *   Violating this rule in an implementation leads to [handleUncaughtCoroutineException] being called with a
     *   [CompletionHandlerException] wrapping the thrown exception.
     * - Is fast, non-blocking, and thread-safe.
     * - Can be invoked concurrently with the surrounding code.
     * - Can be invoked from any context.
     *
     * The meaning of `cause` that is passed to the handler is:
     * - It is `null` if the continuation was cancelled directly via [CancellableContinuation.cancel] without a `cause`.
     * - It is an instance of [CancellationException] if the continuation was _normally_ cancelled from the outside.
     *   **It should not be treated as an error**. In particular, it should not be reported to error logs.
     * - Otherwise, the continuation had cancelled with an _error_.
     */
    fun invoke(cause: Throwable?)

    /**
     * A lambda passed from outside the coroutine machinery.
     *
     * See the requirements for [CancelHandler.invoke] when implementing this function.
     */
    class UserSupplied(private val handler: (cause: Throwable?) -> Unit) : CancelHandler {