gpt4 book ai didi

scala Actor : drop messages if queue is too long?

转载 作者:行者123 更新时间:2023-12-01 23:08:46 26 4
gpt4 key购买 nike

如果 Actor 的邮箱太满,我想从 Actor 的邮箱中删除消息。例如,如果队列大小达到 1000 条消息,则应删除最旧的消息。

最佳答案

不能直接使用邮箱,但可以实现Message Expiration现有库之上的模式。

在每条消息中发送创建日期:

case class ExpirableMessage(msg: String, createdAt: Long) 

reactWithin(0)扫描邮箱,过滤掉过期邮件:

react{ 
case msg: ExpirableMessage =>
// handle the message
// clean the mailbox with nested react
reactWithin(0){
case ExpirableMessage(_, createdAt) if(currentTimeMillis - createdAt > INTERVAL) =>
case TIMEOUT =>
}
}

关于scala Actor : drop messages if queue is too long?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6070666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com