title: What is the correct way to perform side effects in a clojure atom swap
body: <p>I'm keeping a registry of processes in an atom. </p>
  
  <p>I want to start one and only one process (specifically a core.async go-loop) per <code>id</code>.</p>
  
  <p>However, you're not supposed to perform side-effects in a <code>swap!</code>, so this code is no good:</p>
  
  <pre><code>(swap! processes-atom
         (fn [processes]
           (if (get processes id)
             processes ;; already exists, do nothing
             (assoc processes id (create-process! id)))))
  </code></pre>
  
  <p>How would I go about doing this correctly?</p>
  
  <p>I have looked at <code>locking</code>, which takes an object as a monitor for the lock. I would prefer that each <code>id</code> - which are dynamic - have their own lock.</p>