dart<P, R> static method

Future<R> dart<P, R>(
  1. R computation(
    1. P params
    ),
  2. P params
)

在 Dart 隔离区中执行计算

Implementation

static Future<R> dart<P, R>(
  R Function(P params) computation,
  P params,
) async {
  final (receivePort, completer) = _setupCommunication<R>();
  final message = {
    'sendPort': receivePort.sendPort,
    'computation': computation,
    'params': params,
  };

  _listen(receivePort, completer);
  try {
    await Isolate.spawn(_isolateEntryPoint, message);
  } catch (e) {
    receivePort.close();
    throw Exception('Error starting isolate: ${e.toString()}');
  }

  return await completer.future;
}