Process<I, O, CR> class
Creates a new process and runs your code in parallel.
Args
Generic | Description |
---|---|
I |
Input Type |
O |
Output Type |
CR |
Common Resource (see ParallelizationInterface Note) |
Note
-
Things like creating a HttpClient takes quiet a bit of time, so closing/reopening it each input is a bad idea. So, instead you create a common resource record in the setupProcess to bundle such high-cost setup operations. The output will be passed to all calls of processInput.
// Generate high-cost resources like HttpClient. // Creating a "record" with field names. var commonResources = (id: 10, name: 'Example', client: httpClient);
-
You destructure the record in processInput to access the high-cost resources while processing inputs.
// Full unpacking of a record. var (id, name, client) = commonResourceRecord; // field access of a record. var client = commonResourceRecord.client; // Do Processing
-
The shutdownProcess is used to clean up resources after processing is done.
- Implemented types
-
- ParallelizationInterface<
I, O, CR>
- ParallelizationInterface<
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isActive → bool
-
Weather the process is still accepting inputs.
no setter
-
processingIsComplete
→ Future<
void> -
Returns
null
when all processing is completed.no setteroverride -
processInput
→ Future<
O> Function(I input, CR setupRecord) -
Callback used for processing individual inputs sent to the spawned process.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
setupProcess
→ Future<
CR> Function() -
Generate common resources required to process individual inputs. The outputs are passed to all
calls of processInput.
final
- shutdownCode → String
-
Shutdown code for the spawned Isolate.
final
-
shutdownProcess
→ Future<
void> Function(CR commonResourceRecord) -
Callback used for cleaning up any resources generated in setupProcess after processing
is done.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
process(
I input) → Future< O> -
Process the given input in a the spawned process.
override
-
shutdownNow(
) → Future< void> -
Kill the spawned process immediately irrespective of weather the current inputs are processed
or not.
override
-
shutdownOnCompletion(
) → Future< void> -
Kill the spawned process after processing current items in queue.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited