IO: add reader/writer parent job parameter
diff --git a/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ReaderJob.kt b/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ReaderJob.kt
index 14173ec..8b98788 100644
--- a/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ReaderJob.kt
+++ b/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/ReaderJob.kt
@@ -22,8 +22,9 @@
fun reader(coroutineContext: CoroutineContext,
channel: ByteChannel,
+ parent: Job? = null,
block: suspend ReaderScope.() -> Unit): ReaderJob {
- val newContext = newCoroutineContext(coroutineContext)
+ val newContext = newCoroutineContext(coroutineContext, parent)
val coroutine = ReaderCoroutine(newContext, channel)
coroutine.initParentJob(newContext[Job])
block.startCoroutine(coroutine, coroutine)
@@ -32,7 +33,8 @@
fun reader(coroutineContext: CoroutineContext,
autoFlush: Boolean = false,
- block: suspend ReaderScope.() -> Unit): ReaderJob = reader(coroutineContext, ByteChannel(autoFlush), block)
+ parent: Job? = null,
+ block: suspend ReaderScope.() -> Unit): ReaderJob = reader(coroutineContext, ByteChannel(autoFlush), parent, block)
private class ReaderCoroutine(context: CoroutineContext, channel: ByteChannel)
: ByteChannelCoroutine(context, channel), ReaderJob, ReaderScope
diff --git a/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/WriterJob.kt b/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/WriterJob.kt
index 372f493..aceb24c 100644
--- a/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/WriterJob.kt
+++ b/core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/WriterJob.kt
@@ -22,8 +22,9 @@
fun writer(coroutineContext: CoroutineContext,
channel: ByteChannel,
+ parent: Job? = null,
block: suspend WriterScope.() -> Unit): WriterJob {
- val newContext = newCoroutineContext(coroutineContext)
+ val newContext = newCoroutineContext(coroutineContext, parent)
val coroutine = WriterCoroutine(newContext, channel)
coroutine.initParentJob(newContext[Job])
block.startCoroutine(coroutine, coroutine)
@@ -32,7 +33,8 @@
fun writer(coroutineContext: CoroutineContext,
autoFlush: Boolean = false,
- block: suspend WriterScope.() -> Unit): WriterJob = writer(coroutineContext, ByteChannel(autoFlush), block)
+ parent: Job? = null,
+ block: suspend WriterScope.() -> Unit): WriterJob = writer(coroutineContext, ByteChannel(autoFlush), parent, block)
private class WriterCoroutine(ctx: CoroutineContext, channel: ByteChannel)
: ByteChannelCoroutine(ctx, channel), WriterScope, WriterJob