Fork me on GitHub

I want to ensure that all my mutations run "synchronously" (one-at-a-time, to completion, across all threads) so I won't have to worry about some race conditions--does anybody have a recommended way of doing this? perhaps by wrapping my call to (parser env tx) with some kind of mutex if tx is a mutation?


@lgessler you can do something like that:

(def single-parser
  (let [in (async/chan)]
      (loop []
        (when-let [{:keys [env tx out]} (async/<!! in)]
          (async/>!! out (parser env tx))

  (defn handler 
    (let [out (async/chan)]
      (async/>!! single-parser {:env env :tx tx :out out})
      (async/!! out))))
Or try to use "wrap-mutation-plugin" to make it serial, but only if it is a mutation call But why mutation races are a problem? All that solutions will only work in a single machine, they do not scale

👍 2
clojure-spin 2

thanks, that looks like a good solution! yeah, I'm OK with all the downsides (single-node, low write throughput) for now--it's just more important that I get this correct and shipped atm