Skip to content

Commit

Permalink
Handle SendPort initialization
Browse files Browse the repository at this point in the history
Use a Completer to await the initial SendPort reception. This change ensures proper initialization of the SendPort before performing inference.
  • Loading branch information
petrkaderabek authored May 19, 2024
1 parent 1472c73 commit a9b4174
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/src/isolate_interpreter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ class IsolateInterpreter {
_receivePort.sendPort,
debugName: debugName,
);

final Completer<SendPort> sendPortCompleter = Completer<SendPort>();

_stateSubscription = _receivePort.listen((state) {
if (state is SendPort) {
_sendPort = state;
sendPortCompleter.complete(_sendPort);
}

if (state is IsolateInterpreterState) {
_state = state;
}
});

await sendPortCompleter.future;
}

// Main function for the spawned isolate.
Expand Down

0 comments on commit a9b4174

Please sign in to comment.