dotnet/orleans

[Proposal] `IGrainTimer` interface for updatable grain timers

ReubenBond opened this issue · 0 comments

This proposal aligns IGrainTimer more closely with Timer from the BCL, granting users a couple of useful additions:

  1. Grain timer dueTime and period can be changed after the timer has been created.
  2. 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 the Change(dueTime, period) style of ITimer from the BCL
  • Update RegisterTimer methods to return IGrainTimer instead of just IDisposable
  • Internally, rewrite GrainTimer, which is the class which implements IGrainTimer to support this functionality, and update consumers to accommodate.