0
我正在实施一个有多个状态的演员,并且使用Stash
不会丢失任何消息。我的状态正在初始化(从数据库中获取某些内容),运行(处理请求)和更新(更新我的状态)。 我的问题是,当我尝试unstashAll()
未来解决时,我输了消息。akka unstashAll不工作
def initializing: Receive = {
case Initialize =>
log.info("initializing")
(for {
items1 <- db.getItems("1")
items2 <- db.getItems("2")
} yield items1 ::: items2) map {items =>
unstashAll()
context.become(running(items))
}
case r =>
log.debug(s"actor received message: $r while initializing and stashed it for further processing")
stash()}
我改变我实现这个
def initializing: Receive = {
case Initialize =>
log.info("initializing")
(for {
items1 <- db.getItems("1")
items2 <- db.getItems("2")
} yield items1 ::: items2) pipeTo self
context.become({
case items: List[Item] =>
unstashAll()
context.become(running(items))
case r =>
log.debug(s"actor received message: $r while initializing and stashed it for further processing")
stash()
})
case r =>
log.debug(s"actor received message: $r while initializing and stashed it for further processing")
stash()}
任何人都可以解释为什么第一个没有工作固定呢?