missionary

mjmeintjes 2021-03-10T01:11:00.002100Z

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.

2021-03-10T09:36:15.004100Z

@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))))))