Solution: Using dispatchers

  • createInvoice does not need to set a dispatcher because postInvoice is a suspending function that does not block threads.
  • sendEmail needs to set the dispatcher to Dispatchers.IO or a custom dispatcher with a thread limit because api is a blocking function.
  • getUserOrders does not need to set a dispatcher because toList is a suspending function that does not block threads.
  • upscaleImage needs to set the dispatcher to Dispatchers.Default or Dispatchers.Default limited to a certain number of threads because upscaling an image is a CPU-intensive operation.