OfflineMutationQueue class
Persistent offline mutation buffer and replay engine.
Stores failed or offline mutations to storage and replays them sequentially FIFO once network connectivity is restored.
Example:
final queue = OfflineMutationQueue(storage: BloomSecureStorage());
queue.registerExecutor('create_post', (payload) => api.createPost(payload));
await queue.enqueue(mutationType: 'create_post', payload: {'title': 'Offline Post'});
final synced = await queue.processQueue();
print('Synced $synced mutations');
Constructors
- OfflineMutationQueue({BloomStorageAdapter? storage})
-
Creates an OfflineMutationQueue with an optional
storageadapter.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether the queue is currently empty.
no setter
- isProcessing → bool
-
Whether the queue is currently in the middle of replaying mutations.
no setter
- length → int
-
Number of mutations currently in queue (alias for queueDepth).
no setter
-
pendingMutations
→ List<
QueuedMutation> -
Unmodifiable list of pending mutations waiting in queue.
no setter
- queueDepth → int
-
Total number of pending mutations currently waiting in queue.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → BloomStorageAdapter?
-
Storage adapter used to persist queued mutations across restarts.
final
Methods
-
clear(
) → Future< void> - Clears all queued mutations from memory and persistent storage.
-
enqueue(
{String? mutationType, String? tag, required Map< String, dynamic> payload, ConflictPolicy conflictPolicy = ConflictPolicy.clientWins}) → Future<String> - Enqueues an optimistic mutation when disconnected.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
persist(
) → Future< void> - Persists current in-memory queue to storage.
-
processQueue(
[FutureOr customHandler(QueuedMutation)?]) → Future< int> - Replays pending mutations sequentially FIFO with conflict policy handling.
-
registerExecutor(
String mutationType, MutationExecutor executor, {CustomConflictResolver? conflictResolver}) → void -
Registers a mutation
executorand optionalconflictResolverfor a givenmutationType. -
restore(
) → Future< void> - Restores persisted mutations from disk storage.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → OfflineMutationQueue
-
Default singleton instance for global application use.
final
- pendingCount → int
-
Total count of pending mutations in the default queue instance.
no setter