假设我有一个 DAPR actor 实现,它涵盖了在单线程循环中实现的长时间运行的操作。演员有两个职责:
类似这样的:
// there can be only one TenantActorWorker
// services.AddTransient<ITenantActorWorker, TenantActorWorker>();
public class TenantActor : Actor
{
private ITenantWorker _worker;
public TenantActor(ActorHost host, ITenantWorker worker)
: base(host)
{
this._worker = worker;
}
public void Process(String tenantId)
{
_worker.WakeUpOrStartFor(tenantId);
}
// ??? how to implement this ??? - there is no "StopActor" like method
public override void StopActor()
{
_worker.Cancel();
}
}
worker实例按原样实现,这里并不重要。重要的是,我必须警告它演员已停用 - 因此也停止处理长操作。是否有任何通知让 Actor 实例在停用(或者最糟糕的是:被重新定位)之前发出警告?
看来
protected override Task OnDeactivateAsync()
可以解决问题。