Skip to content

Commit 339ccf3

Browse files
committed
Public ClosedWriteChannelException and message for it
1 parent 0570f38 commit 339ccf3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ package kotlinx.coroutines.experimental.io
44

55
import kotlinx.coroutines.experimental.CancellableContinuation
66
import kotlinx.coroutines.experimental.channels.ClosedReceiveChannelException
7-
import kotlinx.coroutines.experimental.channels.ClosedSendChannelException
87
import kotlinx.coroutines.experimental.io.internal.*
98
import kotlinx.coroutines.experimental.io.packet.*
109
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
1110
import java.nio.BufferOverflowException
1211
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
1312

13+
internal const val DEFAULT_CLOSE_MESSAGE = "Byte channel was closed"
14+
1415
// implementation for ByteChannel
1516
internal class ByteBufferChannel(
1617
override val autoFlush: Boolean,
@@ -1276,7 +1277,8 @@ internal class ByteBufferChannel(
12761277
c.resume(state.capacity.availableForRead > 0)
12771278
}
12781279

1279-
WriteOp.getAndSet(this, null)?.tryResumeWithException(cause ?: ClosedSendChannelException(null))
1280+
WriteOp.getAndSet(this, null)?.tryResumeWithException(cause ?:
1281+
ClosedWriteChannelException(DEFAULT_CLOSE_MESSAGE))
12801282
}
12811283

12821284
private tailrec suspend fun readSuspend(size: Int): Boolean {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package kotlinx.coroutines.experimental.io
22

3-
import kotlinx.coroutines.experimental.io.packet.*
3+
import kotlinx.coroutines.experimental.io.packet.ByteReadPacket
4+
import kotlinx.coroutines.experimental.io.packet.ByteWritePacket
5+
import kotlinx.coroutines.experimental.io.packet.buildPacket
46
import java.nio.ByteBuffer
57
import java.nio.CharBuffer
68
import java.util.concurrent.CancellationException
@@ -174,4 +176,9 @@ suspend fun ByteWriteChannel.writePacketSuspend(builder: suspend ByteWritePacket
174176
writePacket(buildPacket { builder() })
175177
}
176178

177-
class ClosedWriteChannelException(message: String?) : CancellationException(message)
179+
/**
180+
* Indicates attempt to write on [isClosedForWrite][ByteWriteChannel.isClosedForWrite] channel
181+
* that was closed without a cause. A _failed_ channel rethrows the original [close][ByteWriteChannel.close] cause
182+
* exception on send attempts.
183+
*/
184+
public class ClosedWriteChannelException(message: String?) : CancellationException(message)

0 commit comments

Comments
 (0)