workerEntry function
Entry point for the worker isolate. Must be top-level or static.
mainSendPort is the SendPort of the main isolate's ReceivePort.
The worker sends its own SendPort as the first message, then listens
for WorkerRequest messages and responds with WorkerResponse.
Implementation
void workerEntry(SendPort mainSendPort) {
final receivePort = ReceivePort();
mainSendPort.send(receivePort.sendPort);
late NativeOdbcConnection conn;
try {
conn = NativeOdbcConnection();
} on Object catch (_) {
mainSendPort.send(const InitializeResponse(0, success: false));
return;
}
receivePort.listen((Object? message) {
if (message == 'shutdown') {
conn.dispose();
receivePort.close();
return;
}
if (message is WorkerRequest) {
_handleRequest(message, mainSendPort, conn);
}
});
}