chat-websocket
chat-websocket copied to clipboard
swap! max-id vs reset!
Just curious about the use of swap! on this line, https://github.com/http-kit/chat-websocket/blob/master/src-cljs/main.cljs#L36, where you have
(swap! max-id #(.-id msg))
in case there is concurrency I'm not aware of.
Wouldn't (reset! max-id (.-id msg)) suffice?
Wouldn't (reset! max-id (.-id msg)) suffice?
That's correct. If the swap fn doesn't make any use of the current state (% in this case), then you can be certain that the new value doesn't depend on the old.
Happy to accept a PR on this, though no idea what the state of the repo/example is otherwise or how many people use this.