SyncWorker class
Background reconciliation worker that drains the OfflineOutbox into Supabase when the device is online.
drain() replays queued events into Supabase through per-table handlers
(see _knownReplayTables); rows are marked synced on success and failed
(with an attempt count) on error. Failed rows are retried with exponential
backoff up to OfflineOutbox.maxAttempts, after which they stay failed
for manual retry from the "Needs attention" UI.
Lifecycle:
• start() subscribes to the connectivity stream and triggers a
drain on every online edge transition.
• drain() reads eligible (pending + due-failed) events oldest-first,
calls a per-table replay handler, and marks each row synced/failed.
• stop() cancels the subscription. Idempotent.
Conflict policy (planned, not yet implemented in drain):
• Append-only tables (conversation_messages, review_log): merge
by client_updated_at, no conflict possible.
• Mutable rows (user_topic_progress, learning_sessions.completed_at):
last-write-wins on (row_id, client_updated_at). Server timestamp
ties broken by client wall-clock.
Constructors
- SyncWorker(OfflineOutbox _outbox, SupabaseDatasource _supabase)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
drain(
{int batchSize = 50}) → Future< int> -
Best-effort: drain pending events into Supabase. Re-entrant guard
via
_drainingso an online tick that fires while a previous drain is still in flight is a no-op. Returns the number of events that successfully replayed. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
start(
Stream< bool> onlineStream) → void -
Begin watching connectivity. Each
true(online) tick triggers a drain attempt;falseticks are ignored. Idempotent — calling twice is a no-op. -
stop(
) → Future< void> -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited