• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.channels
6 
7 import kotlinx.coroutines.*
8 import kotlin.coroutines.*
9 
10 @Suppress("DEPRECATION")
11 internal open class ChannelCoroutine<E>(
12     parentContext: CoroutineContext,
13     protected val _channel: Channel<E>,
14     active: Boolean
<lambda>null15 ) : AbstractCoroutine<Unit>(parentContext, active), Channel<E> by _channel {
16     val channel: Channel<E> get() = this
17 
18     override fun cancel() {
19         cancelInternal(defaultCancellationException())
20     }
21 
22     @Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
23     final override fun cancel(cause: Throwable?): Boolean {
24         cancelInternal(defaultCancellationException())
25         return true
26     }
27 
28     final override fun cancel(cause: CancellationException?) {
29         cancelInternal(cause ?: defaultCancellationException())
30     }
31 
32     override fun cancelInternal(cause: Throwable) {
33         val exception = cause.toCancellationException()
34         _channel.cancel(exception) // cancel the channel
35         cancelCoroutine(exception) // cancel the job
36     }
37 }
38