Skip to content

Commit f84f99f

Browse files
committed
Fixed CompletableSource.await and added test for it
1 parent 1b4f2d4 commit f84f99f

File tree

2 files changed

+29
-2
lines changed
  • kotlinx-coroutines-rx2/src

2 files changed

+29
-2
lines changed

kotlinx-coroutines-rx2/src/main/kotlin/kotlinx/coroutines/experimental/rx2/RxAwait.kt

+1-1
Original file line numberDiff line numberDiff 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

kotlinx-coroutines-rx2/src/test/kotlin/kotlinx/coroutines/experimental/rx2/CompletableTest.kt

+28-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package kotlinx.coroutines.experimental.rx2
1818

19-
import kotlinx.coroutines.experimental.CancellationException
2019
import kotlinx.coroutines.experimental.TestBase
2120
import kotlinx.coroutines.experimental.runBlocking
2221
import 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
}

0 commit comments

Comments
 (0)