diff web/rdfdbclient.ts @ 2421:ac55319a2eac

don't drop patches that arrive before we get WS connected
author drewp@bigasterisk.com
date Tue, 21 May 2024 16:10:39 -0700
parents 4556eebe5d73
children
line wrap: on
line diff
--- a/web/rdfdbclient.ts	Tue May 21 14:50:01 2024 -0700
+++ b/web/rdfdbclient.ts	Tue May 21 16:10:39 2024 -0700
@@ -5,7 +5,7 @@
 
 export class RdfDbClient {
   private channel: RdfDbChannel;
-  _patchesToSend: Patch[];
+  private patchesToSend: Patch[];
   // Send and receive patches from rdfdb. Primarily used in SyncedGraph.
   //
   // What this should do, and does not yet, is keep the graph
@@ -19,10 +19,10 @@
     private applyPatch: (p: Patch) => void,
     setStatus: (status: string) => void
   ) {
-    this._patchesToSend = [];
+    this.patchesToSend = [];
     this.channel = new RdfDbChannel(patchSenderUrl);
     this.channel.statusDisplay.subscribe((st: string) => {
-      setStatus(st + `; ${this._patchesToSend.length} pending `);
+      setStatus(st + `; ${this.patchesToSend.length} pending `);
     });
     this.channel.newConnection.subscribe(() => {
       this.clearGraphOnNewConnection();
@@ -40,7 +40,7 @@
 
   sendPatch(patch: Patch) {
     log("queue patch to server ", patch.summary());
-    this._patchesToSend.push(patch);
+    this.patchesToSend.push(patch);
     this._continueSending();
   }
 
@@ -51,11 +51,13 @@
   async _continueSending() {
     // we could call this less often and coalesce patches together to optimize
     // the dragging cases. See rdfdb 'compactPatches' and 'processInbox'.
-    while (this._patchesToSend.length) {
-      const patch = this._patchesToSend.splice(0, 1)[0];
+    while (this.patchesToSend.length) {
+      const patch = this.patchesToSend.splice(0, 1)[0];
       const json = await patch.toJsonPatch();
       const ret = this.channel.sendMessage(json);
       if (!ret) {
+        log('sendMessage failed- retrying')
+        this.patchesToSend.unshift(patch);
         setTimeout(this._continueSending.bind(this), 500);
 
         // this.disconnect()