@syncular/client 0.84.0 → 0.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,6 +235,7 @@ export function startSyncWorkerCore(
235
235
 
236
236
  // -- SPEC §7.5 host loop: event-driven intents, no interactive polling --
237
237
  let autoSync = true;
238
+ let coalesceMs = 0;
238
239
  let autoSyncScheduled = false;
239
240
  let cancelBackground: (() => void) | undefined;
240
241
  let backgroundDue = Number.POSITIVE_INFINITY;
@@ -273,7 +274,7 @@ export function startSyncWorkerCore(
273
274
  // let every wake-up that arrives while this round waits behind the
274
275
  // running one queue its own full drive (§8.4 coalescing).
275
276
  autoSyncScheduled = false;
276
- return running.syncUntilIdle();
277
+ return running.syncUntilIdle({ skipEmpty: true });
277
278
  })
278
279
  .then((summary) => {
279
280
  retryDelayMs = 250;
@@ -344,7 +345,8 @@ export function startSyncWorkerCore(
344
345
  return;
345
346
  }
346
347
  autoSyncScheduled = true;
347
- queueMicrotask(runAutoSync);
348
+ if (coalesceMs > 0) scheduleBackground(runAutoSync, coalesceMs);
349
+ else queueMicrotask(runAutoSync);
348
350
  }
349
351
 
350
352
  function requireClient(): SyncClient {
@@ -383,6 +385,7 @@ export function startSyncWorkerCore(
383
385
  );
384
386
  }
385
387
  autoSync = config.autoSync ?? true;
388
+ coalesceMs = config.coalesceMs ?? 0;
386
389
  headers = config.headers ?? {};
387
390
  const http = { headers: () => headers };
388
391
 
@@ -223,6 +223,11 @@ export interface SyncClientHandleConfig {
223
223
  readonly previousVersionContext?: SyncClientConfig['previousVersionContext'];
224
224
  /** Worker-side host loop (§8.4); default true. */
225
225
  readonly autoSync?: boolean;
226
+ /**
227
+ * §8.4: milliseconds a queued `autoSync` drive waits before it starts, so
228
+ * the claims and writes of one burst ride in one round. Default 0.
229
+ */
230
+ readonly coalesceMs?: number;
226
231
  /**
227
232
  * Default: Web Locks. A runtime without Web Locks refuses the handle with
228
233
  * `client.web_locks_unavailable` unless the host injects a lock.
@@ -1121,6 +1126,9 @@ function buildInitConfig(
1121
1126
  ? { previousVersionContext: config.previousVersionContext }
1122
1127
  : {}),
1123
1128
  ...(config.autoSync !== undefined ? { autoSync: config.autoSync } : {}),
1129
+ ...(config.coalesceMs !== undefined
1130
+ ? { coalesceMs: config.coalesceMs }
1131
+ : {}),
1124
1132
  };
1125
1133
  }
1126
1134
 
@@ -1164,6 +1172,11 @@ export async function createSyncClientHandle(
1164
1172
  config: SyncClientHandleConfig,
1165
1173
  ): Promise<SyncClientHandle> {
1166
1174
  const resolvedConfig = resolveReplicaConfig(config);
1175
+ if (
1176
+ config.coalesceMs !== undefined &&
1177
+ !(Number.isFinite(config.coalesceMs) && config.coalesceMs >= 0)
1178
+ )
1179
+ throw invalidRequest('coalesceMs must be a non-negative finite number');
1167
1180
  const lock = resolvedConfig.leaderLock ?? defaultLeaderLock();
1168
1181
  const lockName = resolvedConfig.lockName ?? 'syncular-leader';
1169
1182
  const invalidation = new InvalidationEmitter();
@@ -160,6 +160,8 @@ export interface WorkerInitConfig {
160
160
  * `syncUntilIdle` rounds inside the worker. Default true.
161
161
  */
162
162
  readonly autoSync?: boolean;
163
+ /** Delay of a queued `autoSync` drive (§8.4); validated by the handle. */
164
+ readonly coalesceMs?: number;
163
165
  }
164
166
 
165
167
  /** Successful init reply. */