Kotlin Actor 到 Actor 的通信

标签 kotlin actor kotlinx.coroutines

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

最佳答案

您需要请求Actor channel , 如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 .

关于Kotlin Actor 到 Actor 的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46995149/

相关文章:

android - Jetpack compose mutableStateOf list 在更改列表项类中的属性值时不会触发重新组合

java - 如何使用内容uri检查文件是否存在

scala - Akka - 公共(public)服务 Actor : Identify or Extension

c# - 字符串 ActorId 的最大长度

database - Akka Actor : Handling DB Failures Without Losing Data

android - 当 getView() 为空时,即在 onCreateView() 之前或 onDestroyView() 之后,无法访问 fragment View 的 LifecycleOwner

java - 如何在ebean中使用多个数据库

kotlin - 将数据从回调推送到 Kotlin 协程的方法是什么

collections - Kotlin 进程收集并行?

kotlin - Kotlin 挂起功能是否在单独的线程上运行?