Skip to content

Instantly share code, notes, and snippets.

@bsless
Created August 28, 2021 06:00
Show Gist options
  • Save bsless/7ecd85183190e6ea30156e33ac63834b to your computer and use it in GitHub Desktop.
Save bsless/7ecd85183190e6ea30156e33ac63834b to your computer and use it in GitHub Desktop.
(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)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment