Skip to content

Commit eee3aaf

Browse files
author
Sergey Mashkov
committed
IO: add ByteReadChannel.cancel
1 parent 15639fa commit eee3aaf

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ByteBufferChannel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ internal class ByteBufferChannel(
9595
return true
9696
}
9797

98+
suspend override fun cancel(cause: Throwable?): Boolean {
99+
return close(cause ?: CancellationException("Channel has been cancelled"))
100+
}
101+
98102
private fun flushImpl(minReadSize: Int, minWriteSize: Int) {
99103
joining?.delegatedTo?.flush()
100104

core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ByteReadChannel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public interface ByteReadChannel {
144144
* @param block to be invoked when at least [min] bytes available for read
145145
*/
146146
suspend fun read(min: Int = 1, block: (ByteBuffer) -> Unit)
147+
148+
suspend fun cancel(cause: Throwable?): Boolean
147149
}
148150

149151
suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean) {

0 commit comments

Comments
 (0)