-
Notifications
You must be signed in to change notification settings - Fork 751
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
Add scheduler extension for actions #518
Add scheduler extension for actions #518
Conversation
/// <param name="state">A state object to be passed to <paramref name="action"/>.</param> | ||
/// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception> | ||
public static IDisposable Schedule<TState>(this IScheduler scheduler, Action<TState> action, TState state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test?
Also the typical signature is state, action
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the signature will create ambiguity with another overload. I will, for the moment, leave the signature as it is but make it internal so it can change without hassle.
In all of my projects (private and in the company) I also add a "MinimalSchedule" extension method which even dismisses the state parameter competely (as generic parameter for the action and parameter for the extension method) and uses Unit.Default instead. Its handy in all cases where the state isn't relevant and isn't used. |
Could you post it? |
@danielcweber yeah, sure. I made a gist for you: https://gist.github.com/Yeah69/41f6c3bcfcfde7cbe53ae178a58bfbbc A little bonus is the async version ;) |
Yes, the signature is up to debate because of possible ambiguity, therefore it is declared internal. |
…Action<TState> and pass a corresponding state object. The ability to pass state will greatly help to reduce the allocations of closures.
This will allow to pass state to a scheduled action to avoid closure allocation and allow for delegate caching.
Note this is based on changes from #515 which should be merged before this PR.