Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] IGrainTimer interface for updatable grain timers #8952

Closed
ReubenBond opened this issue Apr 21, 2024 · 0 comments · Fixed by #8954
Closed

[Proposal] IGrainTimer interface for updatable grain timers #8952

ReubenBond opened this issue Apr 21, 2024 · 0 comments · Fixed by #8954

Comments

@ReubenBond
Copy link
Member

ReubenBond commented Apr 21, 2024

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant