Skip to content

Commit c038d63

Browse files
committed
Improve source-code compatibility with prev version of openChannel().use { ... }
1 parent 6dc049d commit c038d63

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public final class kotlinx/coroutines/experimental/channels/BroadcastChannel$Fac
585585

586586
public final class kotlinx/coroutines/experimental/channels/BroadcastChannelKt {
587587
public static final fun BroadcastChannel (I)Lkotlinx/coroutines/experimental/channels/BroadcastChannel;
588-
public static final synthetic fun use (Lkotlinx/coroutines/experimental/channels/ReceiveChannel;Lkotlin/jvm/functions/Function1;)V
588+
public static final fun use (Lkotlinx/coroutines/experimental/channels/ReceiveChannel;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
589589
}
590590

591591
public final class kotlinx/coroutines/experimental/channels/BroadcastKt {

common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental/channels/BroadcastChannel.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ public interface SubscriptionReceiveChannel<out T> : ReceiveChannel<T>, Closeabl
111111
}
112112

113113
/** @suppress **Deprecated**: Left here for migration from SubscriptionReceiveChannel */
114-
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Use `ReceiveChannel<*>.consume` instead")
115-
public inline fun <E, R> ReceiveChannel<E>.use(block: (ReceiveChannel<E>) -> R) {
114+
@Deprecated(
115+
level = DeprecationLevel.WARNING,
116+
message = "Use `ReceiveChannel<*>.consume` instead",
117+
replaceWith = ReplaceWith("consume { let(block) }")
118+
)
119+
public inline fun <E, R> ReceiveChannel<E>.use(block: (ReceiveChannel<E>) -> R): R {
116120
var exception: Throwable? = null
117121
try {
118-
block(this)
122+
return block(this)
119123
} catch (t: Throwable) {
120124
exception = t
121125
throw t
122-
}
123-
finally {
126+
} finally {
124127
this.cancel(exception)
125128
}
126129
}

0 commit comments

Comments
 (0)