createIsolate function

Future<SqfliteIsolate> createIsolate(
  1. SqfliteFfiInit? ffiInit
)

Create an isolate.

Implementation

Future<SqfliteIsolate> createIsolate(SqfliteFfiInit? ffiInit) async {
  // create a long-lived port for receiving messages
  var ourFirstReceivePort = ReceivePort();

  // spawn the isolate with an initial sendPort.
  await Isolate.spawn(_isolate, [ourFirstReceivePort.sendPort, ffiInit]);

  // the isolate sends us its SendPort as its first message.
  // this lets us communicate with it. we’ll always use this port to
  // send it messages.
  var sendPort = (await ourFirstReceivePort.first) as SendPort;

  return SqfliteIsolate(sendPort: sendPort);
}