-
Notifications
You must be signed in to change notification settings - Fork 7
Parallel Rule Configuration
Arif Yayalar (@ayayalar) edited this page Aug 24, 2018
·
1 revision
Parallel rules can be configured via the ParallelConfiguration
property. The decision to Cancel
on CancellationTokenSource
must be made in the BeforeInvokeAsync
method. Otherwise it will be ignored.
The following are the available configuration options that can be set in the InitializeAsync
method:
TaskCreationOptions : set to TaskCreationOptions.None
by default.
TaskScheduler : set to TaskScheduler.Default
by default.
CancellationTokenSource : is not set.
NestedParallelRulesInherits : if set to true
, nested parallel rule(s) inherits the TaskCreationOptions
and the TaskScheduler
from the containing parallel rule.
class UpdateTaxAsync : RuleAsync<Order>
{
public async override Task InitializeAsync()
{
IsParallel = true;
ParellelConfiguration.TaskCreationOptions = TaskCreationOptions.PreferFairness;
ParellelConfiguration.CancellationTokenSource = new CancellationTokenSource();
ParellelConfiguration.TaskScheduler = TaskScheduler.Current;
await base.InitializeAsync();
}
public async override Task BeforeInvokeAsync()
{
if (Model.Price == 0)
{
// Cancels calling InvokeAsync() if Price equal 0
ParellelConfiguration.CancellationTokenSource.Cancel();
}
await base.BeforeInvokeAsync();
}
public async override Task<IRuleResult> InvokeAsync()
{
Model.Price = UpdatePriceWithTax();
return await RuleResult.Nil();
}
}
var ruleResults = await RuleEngine<Order>.GetInstance(order)
.ApplyRules(new UpdateTaxAsync())
.ExecuteAsync()
Synchronous Rules |
Asynchronous Rules |
Parallel Rules |
Reactive Rules |
Proactive Rules |
ExceptionHandler Rules |