process method
Process the queue (replay mutations)
Replays queued mutations sequentially in strict FIFO order. If a mutation fails (due to network or execution error), processing stops immediately to prevent out-of-order execution in order-sensitive workloads (e.g. chat messages, financial transactions, document edits). The failed job remains at the head of the queue to be retried on the next reconnect.
Implementation
Future<void> process() async {
if (_isProcessing || _queue.isEmpty || !ZenQueryCache.instance.isOnline) {
return;
}
_isProcessing = true;
ZenLogger.logDebug(
'Processing offline mutation queue (${_queue.length} jobs)...');
try {
// Process strictly in order (FIFO)
while (_queue.isNotEmpty && ZenQueryCache.instance.isOnline) {
final job = _queue.first;
try {
await _executeJob(job);
remove(job.id); // Success! Remove from queue.
} catch (e) {
ZenLogger.logError('Failed to replay mutation ${job.id}', e);
// Stop on failure to preserve sequential ordering.
// Remaining jobs will be processed on subsequent reconnect attempts.
break;
}
}
} finally {
_isProcessing = false;
}
}