Hi, I have a hard time wrapping my head about `Cor...
# javascript
h
Hi, I have a hard time wrapping my head about
Coroutines
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:
Copy code
fun fetchUser(): Promise<User>
How would it look to launch a
Coroutine
that calls this function and returns the
Promise
?
Copy code
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
Copy code
const newTokens = await refreshTokenPromise;
since there is no
runBlocking
in KotlinJS and to
.await()
it has to be a suspend function.