Fork me on GitHub
#pathom
<
2021-08-11
>
lgessler17:08:55

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?

souenzzo17:08:15

@lgessler you can do something like that:

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

(comment 
  (defn handler 
    [req]
    (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
lgessler17:08:41

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