New Yjs user here, so apologies if this is a question with an obvious or existing answer.
Suppose I’m working on a whiteboard app, which shows a collection of whiteboard notes that any user can move or edit. Suppose on the board there is a note N1, and that both Alice and Bob want to move it to somewhere else on the board.
Clearly only one user can move N at any time, so I’ll need some sort of distributed lock. My initial thought would be a Y.Map, which maps from note ID (N1) to either
null or the ID of the currently locking user. Once a user has a lock, they are free to move the note, and no other users can get the lock until it becomes free again.
So: both Alice’s client and Bob’s client both try to
set a value into the Y.Map at the same time. At this point, my understanding gets a bit fuzzy. Does one update get rejected because another get there first? Or are both updates accepted, and the latest one wins? Or something else? And what’s the best/correct way for my app to know that potentially conflicting updates have been resolved and that, say, Alice now safely has the lock and can proceed with her move operation (and Bob has to wait)?