Skip to content

GrainBaseExtensions Methods

Helper methods for IGrainBase implementations.

DeactivateOnIdle(IGrainBase)

staticextension
View source
public static void DeactivateOnIdle(this IGrainBase grain)
Deactivate this grain activation after the current grain method call is completed. This call will mark this activation of the current grain to be deactivated and removed at the end of the current method. The next call to this grain will result in a different activation to be used, which typical means a new activation will be created automatically by the runtime.

Parameters

grainIGrainBase

MigrateOnIdle(IGrainBase)

staticextension
View source
public static void MigrateOnIdle(this IGrainBase grain)
Starts an attempt to migrating this instance to another location. Migration captures the current RequestContext, making it available to the activation's placement director so that it can consider it when selecting a new location. Migration will occur asynchronously, when no requests are executing, and will not occur if the activation's placement director does not select an alternative location.

Parameters

grainIGrainBase

RegisterGrainTimer(IGrainBase, Func<CancellationToken, Task>, GrainTimerCreationOptions)

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<CancellationToken, Task>, TimeSpan, TimeSpan)

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
dueTimeTimeSpan
A System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to prevent the timer from starting. Specify System.TimeSpan.Zero to start the timer immediately.
periodTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<Task>, GrainTimerCreationOptions)

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<Task> callback, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<Task>
The timer callback, which will be invoked whenever the timer becomes due.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<Task>, TimeSpan, TimeSpan)

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<Task> callback, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<Task>
The timer callback, which will be invoked whenever the timer becomes due.
dueTimeTimeSpan
A System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to prevent the timer from starting. Specify System.TimeSpan.Zero to start the timer immediately.
periodTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<TState, CancellationToken, Task>, TState, GrainTimerCreationOptions)

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<TState, CancellationToken, Task>, TState, TimeSpan, TimeSpan)

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
dueTimeTimeSpan
The amount of time to delay before invoking the callback.
periodTimeSpan
The time interval between callback invocations.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<TState, Task>, TState, GrainTimerCreationOptions)

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, Task> callback, TState state, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

RegisterGrainTimer(IGrainBase, Func<TState, Task>, TState, TimeSpan, TimeSpan)

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
dueTimeTimeSpan
The amount of time to delay before invoking the callback.
periodTimeSpan
The time interval between callback invocations.

Returns

The IGrainTimer instance which represents the timer.

RunRequestAsync(IGrainBase, Action<CancellationToken>, CancellationToken)

staticextension
View source
public static Task RunRequestAsync(this IGrainBase grain, Action<CancellationToken> callback, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackAction<CancellationToken>
The callback to run.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Action<CancellationToken>, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task RunRequestAsync(this IGrainBase grain, Action<CancellationToken> callback, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackAction<CancellationToken>
The callback to run.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<CancellationToken, Task>, CancellationToken)

staticextension
View source
public static Task RunRequestAsync(this IGrainBase grain, Func<CancellationToken, Task> callback, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The callback to run.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<CancellationToken, Task>, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task RunRequestAsync(this IGrainBase grain, Func<CancellationToken, Task> callback, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The callback to run.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Action<TState, CancellationToken>, TState, CancellationToken)

staticextension
View source
public static Task RunRequestAsync<TState>(this IGrainBase grain, Action<TState, CancellationToken> callback, TState state, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackAction<TState, CancellationToken>
The callback to run.
stateTState
The state passed to the callback.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Action<TState, CancellationToken>, TState, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task RunRequestAsync<TState>(this IGrainBase grain, Action<TState, CancellationToken> callback, TState state, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackAction<TState, CancellationToken>
The callback to run.
stateTState
The state passed to the callback.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<TState, CancellationToken, Task>, TState, CancellationToken)

staticextension
View source
public static Task RunRequestAsync<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task>
The callback to run.
stateTState
The state passed to the callback.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<TState, CancellationToken, Task>, TState, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task RunRequestAsync<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task>
The callback to run.
stateTState
The state passed to the callback.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<CancellationToken, Task<TResult>>, CancellationToken)

staticextension
View source
public static Task<TResult> RunRequestAsync<TResult>(this IGrainBase grain, Func<CancellationToken, Task<TResult>> callback, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task<TResult>>
The callback to run.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<CancellationToken, Task<TResult>>, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task<TResult> RunRequestAsync<TResult>(this IGrainBase grain, Func<CancellationToken, Task<TResult>> callback, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task<TResult>>
The callback to run.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<TState, CancellationToken, Task<TResult>>, TState, CancellationToken)

staticextension
View source
public static Task<TResult> RunRequestAsync<TState, TResult>(this IGrainBase grain, Func<TState, CancellationToken, Task<TResult>> callback, TState state, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task<TResult>>
The callback to run.
stateTState
The state passed to the callback.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.

RunRequestAsync(IGrainBase, Func<TState, CancellationToken, Task<TResult>>, TState, LocalRequestOptions, CancellationToken)

staticextension
View source
public static Task<TResult> RunRequestAsync<TState, TResult>(this IGrainBase grain, Func<TState, CancellationToken, Task<TResult>> callback, TState state, LocalRequestOptions options, CancellationToken cancellationToken = default(CancellationToken))
Runs callback as a request on this grain activation.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task<TResult>>
The callback to run.
stateTState
The state passed to the callback.
optionsLocalRequestOptions
The options for the request.
cancellationTokenCancellationToken
Cancels the request while it is queued. Once the callback starts, the token is passed to the callback.

Returns

A System.Threading.Tasks.Task which completes with the outcome of the callback.