fetchAndActivateConfig function
Fetches from the backend and activates what came back.
Answers false when the fetch succeeded but there was nothing new to activate, which is not a failure.
Implementation
Future<bool> fetchAndActivateConfig() {
final completer = Completer<bool>();
final receive = RawReceivePort();
receive.handler = (Object? message) {
receive.close();
final parts = message! as List<Object?>;
if (parts[0] == true) {
completer.complete((parts[1]! as int) == 1);
} else {
completer.completeError(
RemoteConfigException(
parts[1]! as int,
parts[2]! as String,
'fetchAndActivate',
),
);
}
};
final rc = fdbRcFetchAndActivate(receive.sendPort.nativePort);
if (rc != 0) {
receive.close();
return Future.error(StateError('fetchAndActivate failed ($rc)'));
}
return completer.future;
}