compute method
Compute isolate manager with R
is return type.
You can use callback
to be able to receive many values before receiving
the final result that is returned from the compute method. The final
result will be returned when the callback returns true
.
Ex:
Without callback, the first value received from the Isolate is always the final value:
final result = await isolate.compute(params); // Get only the first result from the isolate
With callback, only the true
value is the final value, so all other values
is marked as the progress values:
final result = await isolate.compute(params, (value) {
if (value is int) {
// Do something here with the value that will be not returned to the `result`.
print('progress: $value');
return false;
}
// The value is not `int` and will be returned to the `result` as the final result.
return true;
});
Implementation
Future<R> compute(P params, {IsolateCallback<R>? callback}) async {
await start();
final queue = IsolateQueue<R, P>(params, callback);
_queues.add(queue);
_excuteQueue();
return queue.completer.future;
}