Paul Woitaschek
01/12/2024, 5:37 PM@Suppress("UNCHECKED_CAST")
public suspend fun <T> Promise<JsAny?>.await(): T = suspendCancellableCoroutine { cont: CancellableContinuation<T> ->
this@await.then(
onFulfilled = { cont.resume(it as T); null },
onRejected = { cont.resumeWithException(it.toThrowableOrNull() ?: error("Unexpected non-Kotlin exception $it")); null }
)
}
Not implemented with type safely like? Also why does it use a cancellable coroutine if the continuation never gets cancelled? Is there something I don’t see?
suspend fun <T : JsAny?> Promise<T>.await(): T = suspendCoroutine { cont: Continuation<T> ->
this@await.then(
onFulfilled = {
cont.resume(it)
null
},
onRejected = {
cont.resumeWithException(
it.toThrowableOrNull()
?: error("Unexpected non-Kotlin exception $it")
)
null
}
)
}
bezrukov
01/12/2024, 9:48 PM