Add macros to thread using promises
wilkerlucio opened this issue · 1 comments
wilkerlucio commented
Hello, first thanks a lot for this project, it makes my like with async so nice :)
There are these 2 macros that I made to help do thread on async operations, they are very helpful to me and I think they could be in the Promesa itself, here they go:
(defmacro p-> [x & forms]
(let [fns (mapv (fn [arg]
(let [[f & args] (if (sequential? arg)
arg
(list arg))]
`(fn [p#] (~f p# ~@args)))) forms)]
`(p/chain (p/promise ~x) ~@fns)))
(defmacro p->> [x & forms]
(let [fns (mapv (fn [arg]
(let [[f & args] (if (sequential? arg)
arg
(list arg))]
`(fn [p#] (~f ~@args p#)))) forms)]
`(p/chain (p/promise ~x) ~@fns)))
With these macros we can thread as if it was sync, but using promises, like:
(p-> (js/fetch "...")
(gobj/get "body"))
If you think this is an interesting addition I can send a PR including tests.
Cheers.
niwinz commented
Interesting, sorry for late response, i was busy and only looked for critical bugs.
They are pretty interesting macros, if you still interested in make a PR, it will be very welcome.