AsyncParallelBatchNode<I, O> class
A class for defining nodes that process a batch of items asynchronously and in parallel.
This class matches Python's AsyncParallelBatchNode behavior:
prepAsync()returns a list of items to processexecAsync(item)processes a single item (override this in subclasses)- The base class handles parallel execution using
Future.wait postAsync()receives the list of results
Example:
class ParallelProcessor extends AsyncParallelBatchNode<int, int> {
@override
Future<List<int>> prepAsync(Map<String, dynamic> shared) async {
return shared['numbers'] as List<int>;
}
@override
Future<int> execAsync(int item) async {
await Future.delayed(Duration(milliseconds: 100));
return item * 2;
}
@override
Future<String> postAsync(
Map<String, dynamic> shared,
dynamic prepResult,
dynamic execResult,
) async {
shared['results'] = execResult;
return 'processed';
}
}
Constructors
-
AsyncParallelBatchNode([AsyncParallelBatchItemExecFunction<
I, O> ? execFunction]) -
Creates a new
AsyncParallelBatchNode.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- log ↔ void Function(String)
-
A function for logging messages.
getter/setter pairinherited
- maxRetries → int
-
The maximum number of times to retry the
execmethod upon failure. A value of 1 means theexecmethod will be attempted once. A value of 2 means it will be attempted once, and if it fails, it will be retried once more.finalinherited - name ↔ String?
-
The unique name of the node.
getter/setter pairinherited
-
params
↔ Map<
String, dynamic> -
The parameters for the node.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
successors
→ Map<
String, BaseNode> -
The successor nodes.
finalinherited
- wait → Duration
-
The duration to wait between retries. If
maxRetriesis greater than 1, this is the amount of time the node will pause before re-attempting theexecmethod.finalinherited
Methods
-
clone(
) → AsyncParallelBatchNode< I, O> -
Creates a copy of this AsyncParallelBatchNode.
override
-
createInstance(
) → BaseNode -
Creates a new instance of AsyncParallelBatchNode.
override
-
exec(
dynamic prepResult) → Future -
The main execution logic for the node.
inherited
-
execAsync(
dynamic prepResult) → Future< List< O> > -
Executes the batch processing in parallel.
override
-
execAsyncItem(
I item) → Future< O> - Processes a single item asynchronously.
-
execFallback(
dynamic prepResult, Exception error) → Future -
A fallback method that is called when the
execmethod fails after all retries have been exhausted.inherited -
execFallbackAsync(
dynamic prepResult, Exception error) → Future -
Async fallback method for when execAsync fails after all retries.
inherited
-
next(
BaseNode node, {String action = 'default'}) → BaseNode -
Defines the next node in the sequence.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
post(
dynamic prepResult, dynamic execResult) → Future -
Post-processing logic after
exec.inherited -
postAsync(
dynamic prepResult, dynamic execResult) → Future -
Post-processes the results after parallel execution.
override
-
prep(
) → Future -
Pre-processing logic before
exec.inherited -
prepAsync(
) → Future< List< I> > -
Prepares the batch of items for processing.
override
-
run(
) → Future -
Sync run method delegates to runAsync for compatibility.
inherited
-
runAsync(
) → Future -
Async version of run that uses the async lifecycle methods.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator -(
String action) → ConditionalTransition -
Creates a conditional transition with the given
action.inherited -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator >>(
BaseNode other) → BaseNode -
Chains the current node to the
othernode.inherited