Skip to content

Commit 0bdecbe

Browse files
change how we ack (codesandbox#3762)
* change how we ack * set initial acknowledged revision * remove try and fix last acknowledged revision
1 parent b762ebd commit 0bdecbe

File tree

1 file changed

+8
-15
lines changed
  • packages/app/src/app/overmind/effects/live

1 file changed

+8
-15
lines changed

packages/app/src/app/overmind/effects/live/clients.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class CodeSandboxOTClient extends OTClient {
4141
) {
4242
super(revision);
4343
this.moduleShortid = moduleShortid;
44+
this.lastAcknowledgedRevision = revision - 1;
4445
this.onSendOperation = onSendOperation;
4546
this.onApplyOperation = onApplyOperation;
4647
}
@@ -65,13 +66,7 @@ export class CodeSandboxOTClient extends OTClient {
6566
})}`,
6667
});
6768

68-
// We make sure to not acknowledge the same revision twice
69-
if (this.lastAcknowledgedRevision < revision) {
70-
this.lastAcknowledgedRevision = revision;
71-
this.serverAck();
72-
} else {
73-
this.resetAwaitSynchronized();
74-
}
69+
this.safeServerAck(revision);
7570
})
7671
.catch(error => {
7772
// If an operation errors on the server we will reject
@@ -98,16 +93,14 @@ export class CodeSandboxOTClient extends OTClient {
9893
}
9994
}
10095

101-
serverAck() {
102-
try {
96+
safeServerAck(revision: number) {
97+
// We make sure to not acknowledge the same revision twice
98+
if (this.lastAcknowledgedRevision < revision) {
99+
this.lastAcknowledgedRevision = revision;
103100
super.serverAck();
104-
105-
this.resetAwaitSynchronized();
106-
} catch (e) {
107-
// Undo the revision increment again
108-
super.revision--;
109-
throw e;
110101
}
102+
103+
this.resetAwaitSynchronized();
111104
}
112105

113106
applyClient(operation: TextOperation) {

0 commit comments

Comments
 (0)