Skip to content

Commit

Permalink
Minor documentation tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Aug 12, 2021
1 parent dfca05f commit e123c8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/flow/Channels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public fun <T> BroadcastChannel<T>.asFlow(): Flow<T> = flow {
* ### Deprecated
*
* **This API is deprecated.** The [BroadcastChannel] provides a complex channel-like API for hot flows.
* [SharedFlow] is a easier-to-use and more flow-centric API for the same purposes, so using
* [SharedFlow] is an easier-to-use and more flow-centric API for the same purposes, so using
* [shareIn] operator is preferred. It is not a direct replacement, so please
* study [shareIn] documentation to see what kind of shared flow fits your use-case. As a rule of thumb:
*
Expand Down
34 changes: 34 additions & 0 deletions kotlinx-coroutines-core/common/test/AsyncTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,38 @@ class AsyncTest : TestBase() {
assertFalse(deferred.isCancelled)
}

@Test
fun testAsyncWithFinally() = runTest {
expect(1)

@Suppress("UNREACHABLE_CODE")
val d = async {
expect(3)
try {
yield() // to main, will cancel
} finally {
expect(6) // will go there on await
return@async "Fail" // result will not override cancellation
}
expectUnreached()
"Fail2"
}
expect(2)
yield() // to async
expect(4)
check(d.isActive && !d.isCompleted && !d.isCancelled)
d.cancel()
check(!d.isActive && !d.isCompleted && d.isCancelled)
check(!d.isActive && !d.isCompleted && d.isCancelled)
expect(5)
try {
d.await() // awaits
expectUnreached() // does not complete normally
} catch (e: Throwable) {
expect(7)
check(e is CancellationException)
}
check(!d.isActive && d.isCompleted && d.isCancelled)
finish(8)
}
}
5 changes: 4 additions & 1 deletion kotlinx-coroutines-core/jvm/test/AsyncJvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import kotlin.test.*


class AsyncJvmTest : TestBase() {
// This must be a common test but it fails on JS because of KT-21961
// We have the same test in common module, but the maintainer uses this particular file
// and semi-automatically types cmd+N + AsyncJvm in order to duck-tape any JVM samples/repros,
// please do not remove this test

@Test
fun testAsyncWithFinally() = runTest {
expect(1)
Expand Down

0 comments on commit e123c8a

Please sign in to comment.