blob: 24e554b8be1788db80af913dcb4c39342b7d59ff [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Sergey Mashkov25b2bc52017-08-24 21:24:47 +03005package kotlinx.coroutines.experimental.io
6
Roman Elizarovf2239e12018-01-10 16:25:25 +03007import kotlinx.coroutines.experimental.*
Roman Elizarov96d7a882017-08-30 15:17:05 +03008import kotlin.coroutines.experimental.CoroutineContext
Sergey Mashkov25b2bc52017-08-24 21:24:47 +03009
10internal open class ByteChannelCoroutine(
11 parentContext: CoroutineContext,
12 open val channel: ByteChannel
13) : AbstractCoroutine<Unit>(parentContext, active = true) {
Roman Elizarov6640b2b2018-01-17 19:08:55 +030014 override fun onCancellation(cause: Throwable?) {
Sergey Mashkov25b2bc52017-08-24 21:24:47 +030015 if (!channel.close(cause) && cause != null)
16 handleCoroutineException(context, cause)
Sergey Mashkov25b2bc52017-08-24 21:24:47 +030017 }
18}