commitAll method

  1. @override
Future<void> commitAll(
  1. [JournalHttpInterface? httpClient,
  2. List<ServiceOfJournal>? forSync]
)
override

Try to commit all servicesForSync.

it change state of services.

Implementation

@override
Future<void> commitAll([
  JournalHttpInterface? httpClient,
  List<ServiceOfJournal>? forSync,
]) async {
  //
  // > main loop, synchronized
  //
  return _lock.synchronized(() async {
    await Future.wait(
      (forSync ?? servicesForSync).map((serv) async {
        ServiceState? state;
        var error = '';
        try {
          (state, error) = await (httpClient ?? httpInterface).sendAdd(serv);
          switch (state) {
            case ServiceState.added: // no changes - do nothing
              log.info('stale service $serv');
            case ServiceState.finished:
              log.finest('finished service $serv');
              _toFinished(serv);
            case ServiceState.rejected:
              log.warning('rejected service $serv');
              _toRejected(serv);
            case ServiceState.outDated:
              throw StateError('commit can not make service outDated');
            case null:
              log.fine('commit stub');
            case ServiceState.removed:
              log.fine('removed service $serv');
          }
          // ignore: avoid_catches_without_on_clauses
        } catch (e) {
          log.severe('Sync services failed: $e');
        }
        if (error.isNotEmpty) showErrorNotification(error);
      }),
    );
  });
}