Fork me on GitHub
Ben Sless06:08:27

Not sure exactly where to ask this, does this make sense to you as an asynchronous middleware for wrapping an asynchronous function around a handler?

(defn wrap-async
  ([af on-success on-failure]
   (wrap-async af identity on-success on-failure))
  ([af before on-success on-failure]
   (fn -wrap [-next]
     (fn -async [ctx respond raise]
       (let [ctx (before ctx)]
         (letfn [(-on-success [result] (-next (on-success ctx result)) respond raise)
                 (-on-failure [?error] (raise (on-failure ctx ?error)))]
           (af ctx -on-success -on-failure)))))))

Ben Sless06:08:48

In this context the async function is af, the handler is -next and the request is ctx