sendToPort static method
- dynamic message
sends a message to the other isolate, which is handled by whatever function was passed to setupIsolateCommunication in that isolate
i.e. background_sendToPort("a") -> main_receiveHandler("a")
values that can be sent are subject to the limitations of SendPort, i.e. primitives and lists/maps thereof
Implementation
static Future<void> sendToPort(dynamic message) async {
final SendPort targetPort = IsolateNameServer.lookupPortByName(
(await isBackgroundIsolate
? _MAIN_ISOLATE_PORT_NAME
: _BACKGROUND_ISOLATE_PORT_NAME));
if (targetPort != null) {
targetPort.send(message);
} else {
throw _SendToPortException(await isBackgroundIsolate);
}
}