start method

Future<void> start()

startup the Processor (creates the underlying isolate)

Args

  • None

Returns

  • None

Errors

  • None

Notes

  • always await this method call, else you'll run into errors due to uninitialized variables

Implementation

Future<void> start() async {
  // !a throw-away port to obtain an inputPort
  var setupPort = ReceivePort();

  // startup the isolate
  var setupList = [
    function,
    _outputPort.sendPort,
    setupPort.sendPort,
  ];

  if (isAsync) {
    _isolate = await Isolate.spawn(_asyncFunctionRunner, setupList);
  } else {
    _isolate = await Isolate.spawn(_syncFunctionRunner, setupList);
  }

  // obtain a port to send inputs to the isolate
  // !this shuts down metaPort
  _inputPort = await setupPort.first;

  // redirect all outputs to the stream
  _outputPort.listen((output) {
    _streamControl.add(output as R);

    // note that the input-output count difference is now decreased by 1
    _inOutDelta -= 1;
  });
}