Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential crashes in asFlow extensions for RxJava 2&3 integrations #2319

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion reactive/kotlinx-coroutines-rx2/src/RxConvert.kt
Expand Up @@ -81,7 +81,12 @@ public fun <T: Any> ObservableSource<T>.asFlow(): Flow<T> = callbackFlow {
val observer = object : Observer<T> {
override fun onComplete() { close() }
override fun onSubscribe(d: Disposable) { if (!disposableRef.compareAndSet(null, d)) d.dispose() }
override fun onNext(t: T) { sendBlocking(t) }
override fun onNext(t: T) {
try {
sendBlocking(t)
} catch (ignored: Exception) { //TODO: Replace when this issue is fixed: https://github.com/Kotlin/kotlinx.coroutines/issues/974
LouisCAD marked this conversation as resolved.
Show resolved Hide resolved
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
}
}
override fun onError(e: Throwable) { close(e) }
}

Expand Down
7 changes: 6 additions & 1 deletion reactive/kotlinx-coroutines-rx3/src/RxConvert.kt
Expand Up @@ -81,7 +81,12 @@ public fun <T: Any> ObservableSource<T>.asFlow(): Flow<T> = callbackFlow {
val observer = object : Observer<T> {
override fun onComplete() { close() }
override fun onSubscribe(d: Disposable) { if (!disposableRef.compareAndSet(null, d)) d.dispose() }
override fun onNext(t: T) { sendBlocking(t) }
override fun onNext(t: T) {
try {
sendBlocking(t)
} catch (ignored: Exception) { //TODO: Replace when this issue is fixed: https://github.com/Kotlin/kotlinx.coroutines/issues/974
}
}
override fun onError(e: Throwable) { close(e) }
}

Expand Down