useIsolate static method

Future useIsolate(
  1. dynamic args,
  2. dynamic functionThatIsToBeRunOnIsolates
)

Implementation

static Future<dynamic> useIsolate(
    args, functionThatIsToBeRunOnIsolates) async {
  final ReceivePort receivePort = ReceivePort();
  try {
    await Isolate.spawn(
        functionThatIsToBeRunOnIsolates, [receivePort.sendPort, args]);
  } on Object {
    debugPrint('Isolate Failed');
    receivePort.close();
  }
  final response = await receivePort.first;

  debugPrint('Result: $response');
  return response;
}