Mercurial > code > home > repos > light9
changeset 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 | d5750b2aaa9e |
children | 62dc1b3644a0 |
files | web/RdfDbChannel.ts web/SyncedGraph.ts web/rdfdbclient.ts |
diffstat | 3 files changed, 19 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/web/RdfDbChannel.ts Tue May 21 14:50:01 2024 -0700 +++ b/web/RdfDbChannel.ts Tue May 21 16:10:39 2024 -0700 @@ -48,6 +48,7 @@ sendMessage(body: string): boolean { // one try, best effort, true if we think it worked if (!this.ws || this.ws.readyState !== this.ws.OPEN) { + log("dropping message: " + body); return false; } log("send patch to server, " + body.length + " bytes");
--- a/web/SyncedGraph.ts Tue May 21 14:50:01 2024 -0700 +++ b/web/SyncedGraph.ts Tue May 21 16:10:39 2024 -0700 @@ -151,22 +151,19 @@ } applyAndSendPatch(patch: Patch) { - console.time("applyAndSendPatch"); if (!this.client) { - log("not connected-- dropping patch"); + throw new Error("no client yet"); + } + if (patch.isEmpty()) { return; } - if (!patch.isEmpty()) { - this._applyPatch(patch); - // // chaos delay - // setTimeout(()=>{ - if (this.client) { - log("sending patch:\n", patch.dump()); - this.client.sendPatch(patch); - } - // },300*Math.random()) - } - console.timeEnd("applyAndSendPatch"); + this._applyPatch(patch); + // // chaos delay + // setTimeout(()=>{ + log("sending patch:\n", patch.dump()); + this.client.sendPatch(patch); + + // },300*Math.random()) } _applyPatch(patch: Patch) {
--- 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()