Class ForEachActionWorker<TItem>
A worker that executes a callback once for each item in an IEnumerable<T>. The callback can optionally create child workers, which will be removed after each iteration, except on the last iteration, allowing them to be inspected.
Less commonly, child workers can also be added (typically by the worker parent) before the worker runs, in which case they will run on the first iteration (if any), but not on later iterations.
Any failure status returned from the user callback or escalated from worker children
will halt the iteration. One can suppress Error
escalation on selected child workers
(by setting EscalateError to false), e.g. to implement retry-on-error
functionality.
Note that if a dedicated parent worker is not needed (e.g. to group child workers), and all
child workers can be created before any child worker is started,
it is simpler to instead use a regular foreach
statement to perform the work,
e.g. creating child workers. See
Instantiating Workers via Looping
for details.
Implements
Inherited Members
Namespace: actionETL
Assembly: actionETL.dll
Syntax
public class ForEachActionWorker<TItem> : WorkerBase<ForEachActionWorker<TItem>>, IDisposeOnFinished
Type Parameters
Name | Description |
---|---|
TItem | The type of each item in the |
Constructors
ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Action<ForEachActionWorker<TItem>, TItem>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an action synchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Action<ForEachActionWorker<TItem>, TItem> iterateAction)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Action<ForEachActionWorker<TItem>, TItem> | iterateAction | The synchronous action to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an function synchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> | iterateFunc | The synchronous function to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an function asynchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> | iterateFuncAsync | The asynchronous function to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an action asynchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, Task> | iterateActionAsync | The asynchronous action to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Action<ForEachActionWorker<TItem>, TItem>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an action synchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Action<ForEachActionWorker<TItem>, TItem> iterateAction)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Action<ForEachActionWorker<TItem>, TItem> | iterateAction | The synchronous action to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an function synchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> | iterateFunc | The synchronous function to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an function asynchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> | iterateFuncAsync | The asynchronous function to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task>)
Initializes a new instance of the ForEachActionWorker<TItem> worker
that will execute an action asynchronously once for each item in an IEnumerable<T>
.
Declaration
public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
IEnumerable<TItem> | enumerable | The enumerable that the worker will iterate over. |
Func<ForEachActionWorker<TItem>, TItem, Task> | iterateActionAsync | The asynchronous action to execute each iteration, optionally creating child workers. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
Methods
RunAsync()
This method can be overridden to add custom functionality to the derived worker that runs before
and after the main processing. In this case, the base class base.RunAsync()
must
be called for the worker to function correctly.
Typically, this worker is used without overriding this method.
Declaration
protected override Task<OutcomeStatus> RunAsync()
Returns
Type | Description |
---|---|
Task<OutcomeStatus> | A |