Skip to content

Commit 1e40237

Browse files
author
Sergey Mashkov
committed
IO: update ByteReadChannel.cancel/close documentation
1 parent a26b790 commit 1e40237

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ public interface ByteReadChannel {
145145
*/
146146
suspend fun read(min: Int = 1, block: (ByteBuffer) -> Unit)
147147

148+
/**
149+
* Close channel with optional [cause] cancellation. Unlike [ByteWriteChannel.close] that could close channel
150+
* normally, cancel does always close with error so any operations on this channel will always fail
151+
* and all suspensions will be resumed with exception.
152+
*
153+
* Please note that if the channel has been provided by [reader] or [writer] then the corresponding owning
154+
* coroutine will be cancelled as well
155+
*
156+
* @see ByteWriteChannel.close
157+
*/
148158
fun cancel(cause: Throwable? = null): Boolean
149159
}
150160

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public interface ByteWriteChannel {
129129
* all subsequent write operations throw [ClosedWriteChannelException] or the specified [cause].
130130
* However, [isClosedForRead][ByteReadChannel.isClosedForRead] on the side of [ByteReadChannel]
131131
* starts returning `true` only after all written bytes have been read.
132+
*
133+
* Please note that if the channel has been closed with cause and it has been provided by [reader] or [writer]
134+
* coroutine then the corresponding coroutine will be cancelled with [cause]. If no [cause] provided then no
135+
* cancellation will be propagated.
132136
*/
133137
public fun close(cause: Throwable? = null): Boolean
134138

0 commit comments

Comments
 (0)