File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 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
3636 subscribe(object : CompletableObserver {
3737 override fun onSubscribe (d : Disposable ) { cont.disposeOnCompletion(d) }
3838 override fun onComplete () { cont.resume(Unit ) }
39- override fun onError (e : Throwable ) { cont.tryResumeWithException (e) }
39+ override fun onError (e : Throwable ) { cont.resumeWithException (e) }
4040 })
4141}
4242
Original file line number Diff line number Diff line change 1616
1717package kotlinx.coroutines.experimental.rx2
1818
19- import kotlinx.coroutines.experimental.CancellationException
2019import kotlinx.coroutines.experimental.TestBase
2120import kotlinx.coroutines.experimental.runBlocking
2221import kotlinx.coroutines.experimental.yield
@@ -83,4 +82,32 @@ class CompletableTest : TestBase() {
8382 yield ()
8483 finish(6 )
8584 }
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+ }
86113}
You can’t perform that action at this time.
0 commit comments