create<T> static method

Future<Agent<T>> create<T>(
  1. T func()
)

Creates the Agent whose initial state is the result of executing func.

Implementation

static Future<Agent<T>> create<T>(T Function() func) async {
  ReceivePort receivePort = ReceivePort();
  Isolate isolate =
      await Isolate.spawn(_isolateMain<T>, receivePort.sendPort);
  SendPort sendPort = await receivePort.first;
  sendPort.send(_Command(_Commands.init, arg0: func));
  receivePort.close();
  return Agent<T>._(isolate, sendPort);
}