http-kit / chat-websocket

Realtime chat by utilizing http-kit's websocket support
36 stars 9 forks source link

swap! max-id vs reset! #2

Open theronic opened 8 years ago

theronic commented 8 years ago

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?

ptaoussanis commented 8 years ago

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.