Hildebrandt Tobias
02/16/2024, 4:18 PMCoroutines with Promises.
Promises are an async callback construct, so in my mind it would make sense to use them with Coroutines
For simplicity, let's say we have this function from a 3rd party lib:
fun fetchUser(): Promise<User>
How would it look to launch a Coroutine that calls this function and returns the Promise?
fun mustReturnPromise: Promise<User> {
// ?
CoroutineScope(CoroutineName("")).launch {
// ?
fetchUser()
}
return // ?
}
For a more concise case I tried to follow this when implementing Aaxios interceptors, but I am somewhat stuck at
const newTokens = await refreshTokenPromise;
since there is no runBlocking in KotlinJS and to .await() it has to be a suspend function.