Fix crash caused by double resume

This commit is contained in:
Mygod
2023-03-10 00:18:56 -05:00
parent 252bf51b7d
commit 3824cac335

View File

@@ -42,6 +42,7 @@ import java.net.NetworkInterface
import java.net.SocketException import java.net.SocketException
import java.net.URL import java.net.URL
import java.util.Locale import java.util.Locale
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException import kotlin.coroutines.resumeWithException
tailrec fun Throwable.getRootCause(): Throwable { tailrec fun Throwable.getRootCause(): Throwable {
@@ -274,7 +275,7 @@ suspend fun <T> connectCancellable(url: String, block: suspend (HttpURLConnectio
return suspendCancellableCoroutine { cont -> return suspendCancellableCoroutine { cont ->
val job = GlobalScope.launch(Dispatchers.IO) { val job = GlobalScope.launch(Dispatchers.IO) {
try { try {
cont.resume(block(conn)) { cont.resumeWithException(it) } cont.resume(block(conn))
} catch (e: Throwable) { } catch (e: Throwable) {
cont.resumeWithException(e) cont.resumeWithException(e)
} finally { } finally {