I would like to use missionary with sieppari. I Was thinking of implementing something similar to: https://github.com/metosin/sieppari/blob/develop/src/sieppari/async/core_async.cljc But I guess that with missionary this is not possible to do; or at least risky because m/? can only be run once outside an m/sp block. Ideas/comments?
my first attempt looks promising
(declare async)
(deftype TaskContext [task]
sa/AsyncContext
(async? [_] true)
(continue [_ f]
(async (m/sp (f (m/? task)))))
(catch [_ f]
(async (m/sp (try (m/? task)
(catch #?(:clj Throwable :cljs :default) e
(f e))))))
#?(:clj (await [_] (m/? task))))
(def async ->TaskContext)
(comment
(s/execute
[{:enter #(update-in % [:request :x] inc)}
{:leave #(async (m/sp (update-in % [:response :x] / 10)))}
{:enter #(async (m/sleep 1000 %))}
identity]
{:x 40})
;; {:x 41/10} after 1s
)I can't imagine how await could be called from an sp context.
However if it's a legitimate scenario that would be a good motivation for option 2 here https://github.com/leonoel/missionary/issues/127
Oh nice!
I will play around with this implementation. I think it could be huge because Web Server stuff is a lot about async behavior. And interceptors are much better for that than ring middlewares.