Kotlin Actor - Suspend while processing message, is next message processed?


#1

Hello,

I have a question regarding the actors of kotlinx.coroutines:

Suppose I have a actor like

val act = actor<String>(capacity = Channel.UNLIMITED) {
  for (msg in channel) when(msg) {
    "delay" -> delay(5000L)
    "print" -> println("print")
  }
}

I now execute

act.offer("delay")
act.offer("print")

What will happen?
Does println print immediately or after 5 seconds?
-> Does a suspending call (job.await(), delay, yield etc) in the message loop blocks the channel until completed or not?

Sorry if this is simple/silly question, I cannot put my head around this.


#2

Welp, it’s gotten late.
Of course I could just test it, which I did.
-> Yes, the channel is blocked (“print” is printed after 5secs).