MCPcopy
hub / github.com/dexie/Dexie.js / continueUsingPollPattern

Function continueUsingPollPattern

addons/Dexie.Syncable/src/connect-protocol.js:330–434  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

328
329 // Poll Pattern
330 function continueUsingPollPattern() {
331 function syncAgain() {
332 getLocalChangesForNode_autoAckIfEmpty(
333 node,
334 function (
335 changes,
336 remoteBaseRevision,
337 partial,
338 nodeModificationsOnAck
339 ) {
340 protocolInstance.sync(
341 node.syncContext,
342 url,
343 options,
344 remoteBaseRevision,
345 node.appliedRemoteRevision,
346 changes,
347 partial,
348 applyRemoteChanges,
349 onChangesAccepted,
350 onSuccess,
351 onError
352 );
353
354 function onChangesAccepted() {
355 Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {
356 Dexie.setByKeyPath(
357 node,
358 keyPath,
359 nodeModificationsOnAck[keyPath]
360 );
361 });
362 node.save().catch('DatabaseClosedError', () => {});
363 }
364
365 function onSuccess(continuation) {
366 if (!connectedContinuation) {
367 // Got disconnected before succeeding. Quit.
368 return;
369 }
370 connectedContinuation = continuation;
371 if (partial) {
372 // We only sent partial changes. Need to do another round asap.
373 syncAgain();
374 } else {
375 // We've sent all changes now (in sync!)
376 if (
377 !isNaN(continuation.again) &&
378 continuation.again < Infinity
379 ) {
380 // Provider wants to keep polling. Set Status to ONLINE.
381 changeStatusTo(Statuses.ONLINE);
382 setTimeout(function () {
383 if (connectedContinuation) {
384 changeStatusTo(Statuses.SYNCING);
385 syncAgain();
386 }
387 }, continuation.again);

Callers 1

continueSendingChangesFunction · 0.85

Calls 3

syncAgainFunction · 0.85
changeStatusToFunction · 0.85
disconnectMethod · 0.65

Tested by

no test coverage detected