Endre Deak
11/03/2021, 7:11 PMsuspend fun callback() { ... }
suspend fun execute(request: Request): Response {
    val response = ... 
    callback()
    
    return response
}Endre Deak
11/03/2021, 7:23 PMstreetsofboston
11/03/2021, 7:43 PMfun CoroutineScope.execute(request: Request, callback: suspend () -> Unit) {
  val response: Response = ...
  launch { callback() }
  return response
}Endre Deak
11/03/2021, 8:33 PMEndre Deak
11/03/2021, 10:30 PMsuspend fun execute(request: Request, callback: suspend () -> Unit): Response = withContext(Dispatchers.Default) {
   val response : Response = ...
   launch { callback() }
   response
}Endre Deak
11/03/2021, 10:40 PMNick Allen
11/03/2021, 11:23 PMwithContext will wait for all child coroutines to finish (read up on structured concurrency for why).
In general it's not a great idea to have a suspend function that returns before it's finished all the work it started. Usually a method is either suspend or it takes a CoroutineScope somehow, usually not both.
What warnings in ide did you get? Is the ... stuff suspending code?Nick Allen
11/03/2021, 11:28 PMval job = Job(); job.join()) and check that the other function returns without giving the signal (job.complete()).Endre Deak
11/04/2021, 6:09 AM