sync method

Future<void> sync()

Implementation

Future<void> sync() async {
  if (_isSyncing) return;
  _isSyncing = true;

  try {
    final unsent = await store.getUnsentOperations();
    await transport.push(unsent);

    for (final op in unsent) {
      await store.markOperationSent(op.opId);
    }

    final incoming = await transport.pull();

    for (final op in incoming) {
      if (!await store.isApplied(op.opId)) {
        await store.applyOperation(op);
      }
    }
  } finally {
    _isSyncing = false;
  }
}