File tree 3 files changed +39
-2
lines changed
3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ public fun <T> BroadcastChannel<T>.asFlow(): Flow<T> = flow {
182
182
* ### Deprecated
183
183
*
184
184
* **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
186
186
* [shareIn] operator is preferred. It is not a direct replacement, so please
187
187
* study [shareIn] documentation to see what kind of shared flow fits your use-case. As a rule of thumb:
188
188
*
Original file line number Diff line number Diff line change @@ -266,4 +266,38 @@ class AsyncTest : TestBase() {
266
266
assertFalse(deferred.isCancelled)
267
267
}
268
268
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
+ }
269
303
}
Original file line number Diff line number Diff line change @@ -8,7 +8,10 @@ import kotlin.test.*
8
8
9
9
10
10
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
+
12
15
@Test
13
16
fun testAsyncWithFinally () = runTest {
14
17
expect(1 )
You can’t perform that action at this time.
0 commit comments