Skip to content

Commit add4b1c

Browse files
committed
Await isolate exit once we try spawning it
1 parent 2d33fa8 commit add4b1c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: packages/powersync_core/lib/src/database/native/native_powersync_database.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class PowerSyncDatabaseImpl
123123
await initialize();
124124
final dbRef = database.isolateConnectionFactory();
125125

126-
Isolate? isolate;
126+
bool triedSpawningIsolate = false;
127127
StreamSubscription<UpdateNotification>? crudUpdateSubscription;
128128
final receiveMessages = ReceivePort();
129129
final receiveUnhandledErrors = ReceivePort();
@@ -136,7 +136,7 @@ class PowerSyncDatabaseImpl
136136
Future<void> waitForShutdown() async {
137137
// Only complete the abortion signal after the isolate shuts down. This
138138
// ensures absolutely no trace of this sync iteration remains.
139-
if (isolate != null) {
139+
if (triedSpawningIsolate) {
140140
await receivedIsolateExit.future;
141141
}
142142

@@ -220,7 +220,8 @@ class PowerSyncDatabaseImpl
220220
});
221221

222222
// Spawning the isolate can't be interrupted
223-
isolate = await Isolate.spawn(
223+
triedSpawningIsolate = true;
224+
await Isolate.spawn(
224225
_syncIsolate,
225226
_PowerSyncDatabaseIsolateArgs(
226227
receiveMessages.sendPort, dbRef, retryDelay, clientParams),

0 commit comments

Comments
 (0)