isolate method

Future isolate(
  1. Future function(
    1. dynamic
    ), {
  2. dynamic args,
})

Implementation

Future<dynamic> isolate(Future Function(dynamic) function,
    {dynamic args}) async {
  if (kIsWeb) {
    return await function(args);
  }
  final ReceivePort receivePort = ReceivePort();
  RootIsolateToken rootToken = RootIsolateToken.instance!;
  await Isolate.spawn<_IsolateData>(
    _isolateEntry,
    _IsolateData(
      token: rootToken,
      function: function,
      answerPort: receivePort.sendPort,
      args: args,
    ),
  );
  return await receivePort.first;
}