Migrate to Kotlin 1.3 coroutines, drop experimental from package
* Features based on version 0.30.0
* Uses Kotlin version 1.3.0-rc-57
* Uses Kotlin/Native version 0.9.2
* Uses AtomicFu 0.11.9-eap13
* Replace SuccessOrFailure with Result
* Replace buildSequence and buildIterator with sequence and iterator
* Apply @BuilderInference on all builders (including extension methods to workaround inference bug)
diff --git a/common/kotlinx-coroutines-core-common/src/channels/Produce.kt b/common/kotlinx-coroutines-core-common/src/channels/Produce.kt
index b7e75de..47bce68 100644
--- a/common/kotlinx-coroutines-core-common/src/channels/Produce.kt
+++ b/common/kotlinx-coroutines-core-common/src/channels/Produce.kt
@@ -2,11 +2,14 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
-package kotlinx.coroutines.experimental.channels
+@file:UseExperimental(ExperimentalTypeInference::class)
-import kotlinx.coroutines.experimental.*
-import kotlinx.coroutines.experimental.channels.Channel.Factory.UNLIMITED
-import kotlin.coroutines.experimental.*
+package kotlinx.coroutines.channels
+
+import kotlinx.coroutines.*
+import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
+import kotlin.coroutines.*
+import kotlin.experimental.*
/**
* Scope for [produce][CoroutineScope.produce] coroutine builder.
@@ -68,10 +71,11 @@
* @param block the coroutine code.
*/
@ExperimentalCoroutinesApi
+@BuilderInference
public fun <E> CoroutineScope.produce(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E> {
val channel = Channel<E>(capacity)
val newContext = newCoroutineContext(context)
@@ -84,12 +88,13 @@
* @suppress **This an internal API and should not be used from general code.**
* onCompletion parameter will be redesigned.
*/
+@BuilderInference
@InternalCoroutinesApi
public fun <E> CoroutineScope.produce(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0,
onCompletion: CompletionHandler? = null,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E> {
val channel = Channel<E>(capacity)
val newContext = newCoroutineContext(context)
@@ -107,13 +112,13 @@
@Deprecated(
message = "Standalone coroutine builders are deprecated, use extensions on CoroutineScope instead",
replaceWith = ReplaceWith("GlobalScope.produce(context, capacity, onCompletion, block)",
- imports = ["kotlinx.coroutines.experimental.GlobalScope", "kotlinx.coroutines.experimental.channels.produce"])
+ imports = ["kotlinx.coroutines.GlobalScope", "kotlinx.coroutines.channels.produce"])
)
public fun <E> produce(
context: CoroutineContext = Dispatchers.Default,
capacity: Int = 0,
onCompletion: CompletionHandler? = null,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E> =
GlobalScope.produce(context, capacity, onCompletion, block)
@@ -125,14 +130,14 @@
@Deprecated(
message = "Standalone coroutine builders are deprecated, use extensions on CoroutineScope instead",
replaceWith = ReplaceWith("GlobalScope.produce(context + parent, capacity, onCompletion, block)",
- imports = ["kotlinx.coroutines.experimental.GlobalScope", "kotlinx.coroutines.experimental.channels.produce"])
+ imports = ["kotlinx.coroutines.GlobalScope", "kotlinx.coroutines.channels.produce"])
)
public fun <E> produce(
context: CoroutineContext = Dispatchers.Default,
capacity: Int = 0,
parent: Job? = null,
onCompletion: CompletionHandler? = null,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E> =
GlobalScope.produce(context + (parent ?: EmptyCoroutineContext), capacity, onCompletion, block)
@@ -142,7 +147,7 @@
context: CoroutineContext = Dispatchers.Default,
capacity: Int = 0,
parent: Job? = null,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E> = GlobalScope.produce(context + (parent ?: EmptyCoroutineContext), capacity, block = block)
/** @suppress **Deprecated**: Binary compatibility */
@@ -150,7 +155,7 @@
public fun <E> produce(
context: CoroutineContext = Dispatchers.Default,
capacity: Int = 0,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ProducerJob<E> =
GlobalScope.produce(context, capacity, block = block) as ProducerJob<E>
@@ -161,7 +166,7 @@
public fun <E> buildChannel(
context: CoroutineContext,
capacity: Int = 0,
- block: suspend ProducerScope<E>.() -> Unit
+ @BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ProducerJob<E> =
GlobalScope.produce(context, capacity, block = block) as ProducerJob<E>