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

Updatable grain timers #8954

Merged
merged 1 commit into from May 16, 2024

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Apr 21, 2024

Fixes #8952

This PR implements the above proposal to align 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.

Here are the key API changes:

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)
  // ...
}

This PR implements 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.
Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond marked this pull request as draft April 21, 2024 01:07
@ReubenBond ReubenBond force-pushed the feature/better-grain-timers branch 5 times, most recently from 5289624 to fb033b5 Compare April 28, 2024 17:20
@ReubenBond ReubenBond marked this pull request as ready for review April 28, 2024 19:08
@ReubenBond ReubenBond force-pushed the feature/better-grain-timers branch 2 times, most recently from 14d43c0 to dcef722 Compare April 28, 2024 19:19
@ReubenBond
Copy link
Member Author

@benjaminpetit PTAL

@ReubenBond
Copy link
Member Author

I will rework this to align it with non-reeentrant timers

@ReubenBond ReubenBond force-pushed the feature/better-grain-timers branch from 82dce05 to 0d150a1 Compare May 15, 2024 16:55
@ReubenBond ReubenBond merged commit a602e92 into dotnet:main May 16, 2024
18 checks passed
@ReubenBond ReubenBond deleted the feature/better-grain-timers branch May 16, 2024 20:26
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 this pull request may close these issues.

[Proposal] IGrainTimer interface for updatable grain timers
2 participants