Fix contact discovery refresh crash.

This commit is contained in:
Cody Henthorne
2022-07-27 12:48:51 -04:00
parent 8cb4034c80
commit 9f4d8ac12c
3 changed files with 54 additions and 16 deletions

View File

@@ -0,0 +1,26 @@
@file:JvmName("RxExtensions")
package org.signal.core.util.concurrent
import io.reactivex.rxjava3.core.Single
import java.lang.RuntimeException
/**
* Throw an [InterruptedException] if a [Single.blockingGet] call is interrupted. This can
* happen when being called by code already within an Rx chain that is disposed.
*
* [Single.blockingGet] is considered harmful and should not be used.
*/
@Throws(InterruptedException::class)
fun <T : Any> Single<T>.safeBlockingGet(): T {
try {
return blockingGet()
} catch (e: RuntimeException) {
val cause = e.cause
if (cause is InterruptedException) {
throw cause
} else {
throw e
}
}
}