Fork me on GitHub
#missionary
<
2021-03-10
>
mjmeintjes01:03:00

What would be the best way to replicate delay using missionary? I'm trying to implement something similar to https://github.com/clojure/core.cache/blob/ee699021b984df182359648312042b79d05cc506/src/main/clojure/clojure/core/cache/wrapped.clj#L38 - cache the results of a task, but also prevent "cache stampeding", ie prevent the task from re-running while the first one is being calculated.

leonoel09:03:15

@mjmeintjes Here's a valid approach, you may need to adapt it to your error handling policy (this one doesn't memoize failures)

(defn lazy-memo [task]
  (let [cache (m/dfv)]
    (m/sp
      (let [this (m/dfv)
            that (cache this)]
        (if (= this that)
          (this (m/? task))
          (m/? that))))))