Skip to content

Commit dd6b5ef

Browse files
author
Sergey Mashkov
committed
Fix byte channel constructor from an array
1 parent 9eaa9c9 commit dd6b5ef

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

kotlinx-coroutines-io/kotlinx-coroutines-io-js/src/main/kotlin/kotlinx/coroutines/experimental/io/ByteChannelJS.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ actual fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteRe
3232
tail = IoBuffer.Pool.borrow()
3333
}
3434

35-
return ByteChannelJS(head, false)
35+
return ByteChannelJS(head, false).apply { close() }
3636
}
3737

3838
/**
@@ -56,7 +56,7 @@ fun ByteReadChannel(content: ArrayBufferView): ByteReadChannel {
5656
tail = IoBuffer.Pool.borrow()
5757
}
5858

59-
return ByteChannelJS(head, false)
59+
return ByteChannelJS(head, false).apply { close() }
6060
}
6161

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

kotlinx-coroutines-io/kotlinx-coroutines-io-native/src/main/kotlin/kotlinx/coroutines/experimental/io/ByteChannelNative.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ actual fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteRe
3333
tail = IoBuffer.Pool.borrow()
3434
}
3535

36-
return ByteChannelNative(head, false)
36+
return ByteChannelNative(head, false).apply { close() }
3737
}
3838

3939
actual suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean) {
@@ -64,7 +64,6 @@ internal class ByteChannelNative(initial: IoBuffer, autoFlush: Boolean) : ByteCh
6464
}
6565
}
6666

67-
6867
override suspend fun readAvailable(dst: CPointer<ByteVar>, offset: Int, length: Int): Int {
6968
return readAvailable(dst, offset.toLong(), length.toLong())
7069
}

kotlinx-coroutines-io/src/test/kotlin/kotlinx/coroutines/experimental/io/ByteChannelSmokeTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,14 @@ open class ByteChannelSmokeTest : ByteChannelTestBase() {
639639
}
640640
}
641641

642+
@Test
643+
fun testConstruct() = runTest {
644+
val channel = ByteReadChannel(ByteArray(2))
645+
channel.readRemaining().use { rem ->
646+
rem.discardExact(2)
647+
}
648+
}
649+
642650
private fun assertEquals(expected: Float, actual: Float) {
643651
if (abs(expected - actual) > 0.000001f) {
644652
kotlin.test.assertEquals(expected, actual)

0 commit comments

Comments
 (0)