I have a graph editor, where user has option to create a node. It gets connected with all currently selected nodes. In google document, it looks like a node (its string label) is mapped to the comma-separated set of connected labels. So, to add a node, I first create an empty map item
map.set(name, "");
and, then, separately add the connected items
if (map.get(a) == null) throw new Error("node " + a + " does not exist") // fails here
if (map.get(b) == null) throw new Error("node " + b + " does not exist")
map.set(a, a_connections)
map.set(b, b_connections)
The problem is that map.get detects that node is not added into the map yet. It takes some time. It seems that the operations are non-blocking even within single JS client (read-my-writes inconsistent). How am I supposed to work with that?
I have noticed this inconsistency when tried to establish two connections (just to detect when connections are failed because it can happen that connection is lost and all my edits do not propagate to server and I wanted to the user to know about that).