Suspend function inside a Coroutine with delay is not working

Viewed 526

I have the following Coroutine which calls a suspending function, adds a delay afterwards and displays the result to user

CoroutineScope(Dispatchers.Main).launch {
   //some initial setup

   val result = service.getResult() //suspend function

   //add a delay of 1s
   delay(1000)

   when(result) {
      ERROR -> {
         Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
      } 
      //other conditions
   }
}

When I add the delay, the code under it never runs. Being a suspending function, delay should work and then rest of the code has to be executed. Not sure what has gone wrong. Any clue?

0 Answers
Related