[Proposal] `IGrainTimer` interface for updatable grain timers
ReubenBond opened this issue · 0 comments
ReubenBond commented
This proposal aligns IGrainTimer
more closely with Timer
from the BCL, granting users a couple of useful additions:
- Grain timer
dueTime
andperiod
can be changed after the timer has been created. - Grain timer can be disposed asynchronously - the disposal task completes after any pending callback complete.
namespace Orleans.Runtime;
// New type, similar to ITimer
public interface IGrainTimer : IDisposable, IAsyncDisposable
{
void Change(TimeSpan dueTime, TimeSpan period);
}
// Update return type from IDisposable to IGrainTimer:
public interface ITimerRegistry
{
IGrainTimer RegisterTimer(IGrainContext grainContext, Func<object?, Task> asyncCallback, object? state, TimeSpan dueTime, TimeSpan period);
}
public abstract class Grain : IGrainBase, IAddressable
{
// ...
protected IGrainTimer RegisterTimer(Func<object?, Task> asyncCallback, object? state, TimeSpan dueTime, TimeSpan period)
// ...
}
To implement the proposal, we will need to do the following:
- Make
IGrainTimer
public - Update
IGrainTimer
to match theChange(dueTime, period)
style ofITimer
from the BCL - Update
RegisterTimer
methods to returnIGrainTimer
instead of justIDisposable
- Internally, rewrite
GrainTimer
, which is the class which implementsIGrainTimer
to support this functionality, and update consumers to accommodate.