dart<P, R> static method
在 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;
}