File tree 2 files changed +29
-2
lines changed
kotlinx-coroutines-rx2/src
main/kotlin/kotlinx/coroutines/experimental/rx2
test/kotlin/kotlinx/coroutines/experimental/rx2
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public suspend fun CompletableSource.await(): Unit = suspendCancellableCoroutine
36
36
subscribe(object : CompletableObserver {
37
37
override fun onSubscribe (d : Disposable ) { cont.disposeOnCompletion(d) }
38
38
override fun onComplete () { cont.resume(Unit ) }
39
- override fun onError (e : Throwable ) { cont.tryResumeWithException (e) }
39
+ override fun onError (e : Throwable ) { cont.resumeWithException (e) }
40
40
})
41
41
}
42
42
Original file line number Diff line number Diff line change 16
16
17
17
package kotlinx.coroutines.experimental.rx2
18
18
19
- import kotlinx.coroutines.experimental.CancellationException
20
19
import kotlinx.coroutines.experimental.TestBase
21
20
import kotlinx.coroutines.experimental.runBlocking
22
21
import kotlinx.coroutines.experimental.yield
@@ -83,4 +82,32 @@ class CompletableTest : TestBase() {
83
82
yield ()
84
83
finish(6 )
85
84
}
85
+
86
+ @Test
87
+ fun testAwaitSuccess () = runBlocking<Unit > {
88
+ expect(1 )
89
+ val completable = rxCompletable(context) {
90
+ expect(3 )
91
+ }
92
+ expect(2 )
93
+ completable.await() // shall launch coroutine
94
+ finish(4 )
95
+ }
96
+
97
+ @Test
98
+ fun testAwaitFailure () = runBlocking<Unit > {
99
+ expect(1 )
100
+ val completable = rxCompletable(context) {
101
+ expect(3 )
102
+ throw RuntimeException (" OK" )
103
+ }
104
+ expect(2 )
105
+ try {
106
+ completable.await() // shall launch coroutine and throw exception
107
+ expectUnreached()
108
+ } catch (e: RuntimeException ) {
109
+ finish(4 )
110
+ assertThat(e.message, IsEqual (" OK" ))
111
+ }
112
+ }
86
113
}
You can’t perform that action at this time.
0 commit comments