简体   繁体   English

Kotlin演员与演员沟通

[英]Kotlin actor to actor communication

An actor can be sent a message with actor.send() or actor.offer() Once my actor gets the message from its channel I'd like to return a response. 可以使用actor.send()actor.offer()向actor发送消息。一旦我的actor从其频道获取消息,我想返回响应。 How do I do this? 我该怎么做呢? I don't see any obvious built in method. 我没有看到任何明显的内置方法。

You need to request the Actor 's channel , as documented : 你需要要求Actorchannel ,为记录

[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 . [ actor coroutine builder]启动从其邮箱通道接收消息的新协程,并作为ActorJob返回对协同程序的ActorJob The resulting object can be used to send messages to this coroutine. 生成的对象可用于向此协程发送消息

Here's a simple example . 这是一个简单的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM