Skip to content

Commit

Permalink
Recover workers not initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Jan 16, 2025
1 parent de8c204 commit db2f8d9
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions sqlite3_web/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,36 +248,52 @@ final class DatabaseClient implements WebSqlite {
}
_startedWorkers = true;

if (globalContext.has('Worker')) {
final dedicated = Worker(
await _startDedicated();
await _startShared();
});
}

Future<void> _startDedicated() async {
if (globalContext.has('Worker')) {
final Worker dedicated;
try {
dedicated = Worker(
workerUri.toString().toJS,
WorkerOptions(name: 'sqlite3_worker'),
);

final (endpoint, channel) = await createChannel();
ConnectRequest(endpoint: endpoint, requestId: 0)
.sendToWorker(dedicated);

_connectionToDedicated =
WorkerConnection(channel.injectErrorsFrom(dedicated));
} else {
} on Object {
_missingFeatures.add(MissingBrowserFeature.dedicatedWorkers);
return;
}

if (globalContext.has('SharedWorker')) {
final shared = SharedWorker(workerUri.toString().toJS);
shared.port.start();
final (endpoint, channel) = await createChannel();
ConnectRequest(endpoint: endpoint, requestId: 0).sendToWorker(dedicated);

final (endpoint, channel) = await createChannel();
ConnectRequest(endpoint: endpoint, requestId: 0)
.sendToPort(shared.port);
_connectionToDedicated =
WorkerConnection(channel.injectErrorsFrom(dedicated));
} else {
_missingFeatures.add(MissingBrowserFeature.dedicatedWorkers);
}
}

_connectionToShared =
WorkerConnection(channel.injectErrorsFrom(shared));
} else {
Future<void> _startShared() async {
if (globalContext.has('SharedWorker')) {
final SharedWorker shared;
try {
shared = SharedWorker(workerUri.toString().toJS);
shared.port.start();
} on Object {
_missingFeatures.add(MissingBrowserFeature.sharedWorkers);
return;
}
});

final (endpoint, channel) = await createChannel();
ConnectRequest(endpoint: endpoint, requestId: 0).sendToPort(shared.port);

_connectionToShared = WorkerConnection(channel.injectErrorsFrom(shared));
} else {
_missingFeatures.add(MissingBrowserFeature.sharedWorkers);
}
}

Future<WorkerConnection> _connectToDedicatedInShared() {
Expand Down

0 comments on commit db2f8d9

Please sign in to comment.