sumAsync function

Future<int> sumAsync(
  1. int a,
  2. int b
)

A longer lived native function, which occupies the thread calling it.

Do not call these kind of native functions in the main isolate. They will block Dart execution. This will cause dropped frames in Flutter applications. Instead, call these native functions on a separate isolate.

Modify this to suit your own use case. Example use cases:

  1. Reuse a single isolate for various different kinds of requests.
  2. Use multiple helper isolates for parallel execution.

Implementation

Future<int> sumAsync(int a, int b) async {
  final SendPort helperIsolateSendPort = await _helperIsolateSendPort;
  final int requestId = _nextSumRequestId++;
  final _SumRequest request = _SumRequest(requestId, a, b);
  final Completer<int> completer = Completer<int>();
  _sumRequests[requestId] = completer;
  helperIsolateSendPort.send(request);
  return completer.future;
}