• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package kotlinx.coroutines.jdk9
2 
3 import kotlinx.coroutines.testing.*
4 import kotlinx.coroutines.*
5 import org.junit.*
6 import java.util.concurrent.Flow as JFlow
7 
8 class AwaitTest: TestBase() {
9 
10     /** Tests that calls to [awaitFirst] (and, thus, to the rest of these functions) throw [CancellationException] and
11      * unsubscribe from the publisher when their [Job] is cancelled. */
12     @Test
13     fun testAwaitCancellation() = runTest {
14         expect(1)
15         val publisher = JFlow.Publisher<Int> { s ->
16             s.onSubscribe(object : JFlow.Subscription {
17                 override fun request(n: Long) {
18                     expect(3)
19                 }
20 
21                 override fun cancel() {
22                     expect(5)
23                 }
24             })
25         }
26         val job = launch(start = CoroutineStart.UNDISPATCHED) {
27             try {
28                 expect(2)
29                 publisher.awaitFirst()
30             } catch (e: CancellationException) {
31                 expect(6)
32                 throw e
33             }
34         }
35         expect(4)
36         job.cancelAndJoin()
37         finish(7)
38     }
39 
40 }