我想定义一个可以与 Akka 演员混合的特征,该演员在一段时间后安排接收超时。这是我想要做的草图......
trait BidderInActivityClearingSchedule[T <: Tradable, A <: Auction[T, A]]
extends ClearingSchedule[T, A] {
this: AuctionActor[T, A] =>
context.setReceiveTimeout(timeout) // can I call this here?
def timeout: FiniteDuration
override def receive: Receive = {
case ReceiveTimeout =>
val (clearedAuction, contracts) = auction.clear
contracts.foreach(contract => settlementService ! contract)
auction = clearedAuction
case message => this.receive(message)
}
}
class FancyAuctionActor[T <: Tradable](val timeout: FiniteDuration, ...)
extends AuctionActor[T, FancyAuctionActor[T]]
with BidderInActivityClearingSchedule[T, FancyAuctionActor[T]]
...但我不明白什么时候context.setReceiveTimeout
会被调用。调用时会作为构造函数的一部分MyFancyAuctionActor
调用吗?timeout
或者它会更早被调用,因此由于尚未定义的事实而引发某种错误。