Skip to content

Commit e123c8a

Browse files
committed
Minor documentation tweaks
1 parent dfca05f commit e123c8a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

kotlinx-coroutines-core/common/src/flow/Channels.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public fun <T> BroadcastChannel<T>.asFlow(): Flow<T> = flow {
182182
* ### Deprecated
183183
*
184184
* **This API is deprecated.** The [BroadcastChannel] provides a complex channel-like API for hot flows.
185-
* [SharedFlow] is a easier-to-use and more flow-centric API for the same purposes, so using
185+
* [SharedFlow] is an easier-to-use and more flow-centric API for the same purposes, so using
186186
* [shareIn] operator is preferred. It is not a direct replacement, so please
187187
* study [shareIn] documentation to see what kind of shared flow fits your use-case. As a rule of thumb:
188188
*

kotlinx-coroutines-core/common/test/AsyncTest.kt

+34
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,38 @@ class AsyncTest : TestBase() {
266266
assertFalse(deferred.isCancelled)
267267
}
268268

269+
@Test
270+
fun testAsyncWithFinally() = runTest {
271+
expect(1)
272+
273+
@Suppress("UNREACHABLE_CODE")
274+
val d = async {
275+
expect(3)
276+
try {
277+
yield() // to main, will cancel
278+
} finally {
279+
expect(6) // will go there on await
280+
return@async "Fail" // result will not override cancellation
281+
}
282+
expectUnreached()
283+
"Fail2"
284+
}
285+
expect(2)
286+
yield() // to async
287+
expect(4)
288+
check(d.isActive && !d.isCompleted && !d.isCancelled)
289+
d.cancel()
290+
check(!d.isActive && !d.isCompleted && d.isCancelled)
291+
check(!d.isActive && !d.isCompleted && d.isCancelled)
292+
expect(5)
293+
try {
294+
d.await() // awaits
295+
expectUnreached() // does not complete normally
296+
} catch (e: Throwable) {
297+
expect(7)
298+
check(e is CancellationException)
299+
}
300+
check(!d.isActive && d.isCompleted && d.isCancelled)
301+
finish(8)
302+
}
269303
}

kotlinx-coroutines-core/jvm/test/AsyncJvmTest.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import kotlin.test.*
88

99

1010
class AsyncJvmTest : TestBase() {
11-
// This must be a common test but it fails on JS because of KT-21961
11+
// We have the same test in common module, but the maintainer uses this particular file
12+
// and semi-automatically types cmd+N + AsyncJvm in order to duck-tape any JVM samples/repros,
13+
// please do not remove this test
14+
1215
@Test
1316
fun testAsyncWithFinally() = runTest {
1417
expect(1)

0 commit comments

Comments
 (0)