Please suggest how to improve this code (and whether it needs to be improved): https://gist.github.com/dottedmag/f38b25718cb151b81ed429312092546b (reformatted slightly, now at rev. 6)
https://gist.github.com/dottedmag/f38b25718cb151b81ed429312092546b#file-resource-id-clj-L27 I would personally don't mix state management within in a let scope
from my pov, doing a swap in a let, it mix side-effects withing the let, which in theory should be just an utility convenenice for having a scope variable`let` imho. Open to see what other think about that
a part of this, Imho instead of if
you could use the or
construct but this is more style
use compare-and-set! instead of swap
using swap! for that kind of thing is asking for a race condition
I might use a semaphore instead of any of that
but I guess a semaphore wouldn't tell you which id is free
you could just use a linkedblockingqueue of ids