Alexey Romanov
Alexey Romanov

Reputation: 170745

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?

Upvotes: 1

Views: 435

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170745

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

Upvotes: 1

Related Questions