jamsocket / aper

A Rust data structure library built on state machines.
https://aper.dev
MIT License
299 stars 12 forks source link

Support local optimistic transitions #4

Closed paulgb closed 3 years ago

paulgb commented 3 years ago

Currently, the client waits to receive a transition back from the server, even if it is waiting for a transition that originated on that client. This is necessary because applying that transition immediately risks a case where another user has issued a conflicting transition at the same time that arrives at the server first, which would cause the local state to be inconsistent.

To get around this, we can keep two copies of the local state: one with only transitions from the server applied to it, and one with local transitions as well. We use the one with local transitions to display the state, but if we ever receive an unexpected transition from the server, we roll back to the local server version.