Problem
I have implemented a system where the frontend and backend make changes to a CRDT document.
The frontend and backend communicate via websockets and at some point the two pairs will synchronise.
The problem is that if the frontend closes the socket without everything being synchronised, the latest changes are never persisted.
How could I pause the closing of the socket until the frontend document and the backend document are synchronised with the latest changes?
Temporary solution
When I detect that the socket is going to close, what I do is ask the backend if the document has the latest change that the frontend has.
To do this I use the getAllChanges function of automerge and see if the hash sent by the frontend exists.
But to do that I have to read all the changes in the document over and over again...