Skip to content

Commit 373d590

Browse files
author
Sergey Mashkov
committed
IO: fixed awaitClose and copyDirect
1 parent 199a04c commit 373d590

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,13 @@ internal class ByteBufferChannel(
10691069

10701070
private suspend fun awaitClose() {
10711071
if (closed != null) return
1072-
joining?.awaitClose() ?: error("Only works for joined")
1072+
val joined = joining
1073+
1074+
if (joined != null) {
1075+
joined.awaitClose()
1076+
} else if (closed == null) {
1077+
error("Only works for joined")
1078+
}
10731079
}
10741080

10751081
internal suspend fun joinFrom(src: ByteBufferChannel, delegateClose: Boolean) {
@@ -1167,6 +1173,7 @@ internal class ByteBufferChannel(
11671173
}
11681174

11691175
if (joining != null) break // TODO think of joining chain
1176+
if (copied >= limit) break
11701177

11711178
// println("readSuspend?")
11721179
if (!src.readSuspend(1)) {

0 commit comments

Comments
 (0)