Search code examples
kotlinkotlinx.coroutines

How best to wait until the actor stops in kotlinx.coroutines 0.20?


In kotlinx.coroutines 0.19, actor returns ActorJob which can be joined:

val myActor = actor<...> { ... }
...
myActor.join()

In 0.20, it's changed to return SendChannel. Looking at the implementation, it does still return an instance of a class which extends Job, so I could write

...
(myActor as Job).join()

but this is an obvious code smell. Is there a better alternative?


Solution

  • What I ended up doing is creating a Channel and then separately launching a Job iterating over this channel.