Akka Actor-等待一段时间,等待消息,否则发送消息 [英] Akka Actor - wait for some time to expect a message, otherwise send a message out

查看:201
本文介绍了Akka Actor-等待一段时间,等待消息,否则发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让 Actor 等待X秒钟以接收任何消息,并且如果接收到消息,则照常进行处理,否则发送消息到其他 Actor (在构造函数中预先确定)?

Is it possible to make an Actor wait for X amount of seconds to receive any message, and if a message is received, process it as usual, otherwise send a message to some other Actor (pre-determined in the constructor)?

推荐答案

是的,如果您想等待任何消息,只需设置 receiveTimeout http://doc.akka.io/docs/akka/current/scala/actors.html#receive-timeout

Yes, if you want to wait for any message, you simply set a receiveTimeout: http://doc.akka.io/docs/akka/current/scala/actors.html#receive-timeout

(此处的文档有些误导,您也可以在每条消息之后设置receiveTimeout)

(The docs is slightly misleading here, you can set the receiveTimeout after every message also)

这篇关于Akka Actor-等待一段时间,等待消息,否则发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆