我找不到有趣的时刻的答案。在akka.net
中,我有调度程序。它将在演员中工作,这些演员会整理出一个数字。
这里是一个简单的实现
_statusScheduler = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
TimeSpan.FromSeconds(_shedulerInterval),
TimeSpan.FromSeconds(_shedulerInterval),
_reporterActor,
new ProgressReport(requestId, _testedQuantity),
Self);
其中
_ shedulerInterval-5秒间隔,
_ testedQuantity-所有时间更新的测试数量。
并且5秒钟后发送0;始终保持不变。这是一个问题:是否可以发送更新的数量?
我无法通过Recieve<>
方法将消息发送到更新数量,因为我的演员被处理了计数消息,并且一直对数量进行计数并对其进行更新(完成后将收到下一条消息)。但是,所有五秒钟我都应该由调度程序生成报告。是否可以修复它?
我认为现在我需要发送所有逻辑,因为它可以正常工作,而我遇到的难题是调度程序行为。
这里的问题是,您每次要发送到调度程序new ProgressReport(requestId, _testedQuantity)
的消息。由于您要按值传递这些整数值,因此对象在创建消息时将具有这些字段的原始值,因此消息将永远不会更新。
如果您希望能够更改定期计划程序中发送的内容,请执行以下操作:
var self = Self; // need a closure here, since ActorContext won't be available
_statusScheduler = Context.System.Scheduler.Advanced.ScheduleRepeatedlyCancelable(interval, interval, () => {
_reporterActor.Tell(new ProgressReport(requestId, _testedQuantity), self);
});
每次调用lambda函数时,此调度程序的用法都会生成一条新消息,因此您可以在对象中包含更新的整数值。