I'm seeing a race condition when attempting to wra...
# coroutines
r
I'm seeing a race condition when attempting to wrap an async api with coroutines, any tips?
Copy code
startRequest() // third party api, async
// sometimes `channel.trySend()` is called before `receive()` is called
val response = channel.receive() // suspends indefinitely
I solved this issue using
async
, is this the right approach? If I don't specify
UNDISPATCHED
then it's still starting the request before
receive()
is called
Copy code
val job = async(start = CoroutineStart.UNDISPATCHED) {
  channel.receive()
}
startRequest()
val response = job.await()