From a9b4174e27392502528a8501890128233cc3120d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kade=C5=99=C3=A1bek?= <46676036+petrkaderabek@users.noreply.github.com> Date: Sun, 19 May 2024 15:25:23 +0200 Subject: [PATCH 1/2] Handle SendPort initialization Use a Completer to await the initial SendPort reception. This change ensures proper initialization of the SendPort before performing inference. --- lib/src/isolate_interpreter.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/isolate_interpreter.dart b/lib/src/isolate_interpreter.dart index ff217a7..79f3fb6 100644 --- a/lib/src/isolate_interpreter.dart +++ b/lib/src/isolate_interpreter.dart @@ -72,16 +72,20 @@ class IsolateInterpreter { _receivePort.sendPort, debugName: debugName, ); - + final Completer sendPortCompleter = Completer(); + _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. From 42311ecbb115f2f7d0fef2be778cdb7166d17bae Mon Sep 17 00:00:00 2001 From: Petr Kaderabek Date: Thu, 30 May 2024 21:39:24 +0200 Subject: [PATCH 2/2] dart format applied --- lib/src/isolate_interpreter.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/isolate_interpreter.dart b/lib/src/isolate_interpreter.dart index 79f3fb6..8956846 100644 --- a/lib/src/isolate_interpreter.dart +++ b/lib/src/isolate_interpreter.dart @@ -73,7 +73,7 @@ class IsolateInterpreter { debugName: debugName, ); final Completer sendPortCompleter = Completer(); - + _stateSubscription = _receivePort.listen((state) { if (state is SendPort) { _sendPort = state; @@ -84,7 +84,7 @@ class IsolateInterpreter { _state = state; } }); - + await sendPortCompleter.future; }