Kotlin actor 到 actor 的通信

Kotlin actor to actor communication

可以使用 actor.send()actor.offer() 向演员发送消息 一旦我的演员从其频道收到消息,我想 return 做出回应。我该怎么做呢?我没有看到任何明显的内置方法。

您需要请求 Actorchannel, 作为 documented:

[The actor coroutine builder] Launches new coroutine that is receiving messages from its mailbox channel and returns a reference to the coroutine as an ActorJob. The resulting object can be used to send messages to this coroutine.

这是一个简单的 example