chat-websocket icon indicating copy to clipboard operation
chat-websocket copied to clipboard

swap! max-id vs reset!

Open theronic opened this issue 9 years ago • 1 comments

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?

theronic avatar Jul 13 '16 13:07 theronic

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.

ptaoussanis avatar Jul 14 '16 03:07 ptaoussanis