diff --git a/src/promesa/core.cljc b/src/promesa/core.cljc index a726cf0..c5d5e86 100644 --- a/src/promesa/core.cljc +++ b/src/promesa/core.cljc @@ -554,8 +554,8 @@ 0 `(impl/resolved nil) 1 `(pt/-promise ~(first exprs)) (reduce (fn [acc e] - `(pt/-mcat (pt/-promise ~e) (fn [_#] ~acc))) - `(pt/-promise ~(last exprs)) + `(pt/-mcat (impl/coerce ~e) (fn [_#] ~acc))) + `(impl/coerce ~(last exprs)) (reverse (butlast exprs))))) (defmacro do @@ -564,7 +564,7 @@ expression." [& exprs] `(pt/-mcat - (pt/-promise nil) + (impl/resolved nil) (fn [_#] (promesa.core/do* ~@exprs)))) @@ -580,7 +580,7 @@ (assert (even? (count bindings)) (str "Uneven binding vector: " bindings)) (c/->> (reverse (partition 2 bindings)) (reduce (fn [acc [l r]] - `(pt/-mcat (pt/-promise ~r) (fn [~l] ~acc))) + `(pt/-mcat (impl/coerce ~r) (fn [~l] ~acc))) `(do* ~@body)))) (defmacro let @@ -589,7 +589,7 @@ [bindings & body] (if (seq bindings) `(pt/-mcat - (pt/-promise nil) + (impl/resolved nil) (fn [_#] (promesa.core/let* ~bindings ~@body))) `(promesa.core/do ~@body))) @@ -599,7 +599,7 @@ [bindings & body] (assert (even? (count bindings)) (str "Uneven binding vector: " bindings)) `(pt/-mcat - (pt/-promise nil) + (impl/resolved nil) (fn [_#] ~(c/let [bindings (partition 2 bindings)] `(c/-> (all ~(mapv second bindings)) diff --git a/src/promesa/impl.cljc b/src/promesa/impl.cljc index 56a7af6..6d1154e 100644 --- a/src/promesa/impl.cljc +++ b/src/promesa/impl.cljc @@ -54,11 +54,11 @@ (.completeExceptionally ^CompletableFuture p v) p))) -#?(:cljs - (defn coerce - "Coerce a thenable to built-in promise impl type." - [v] - (impl/coerce v))) +(defn coerce + [v] + (if (promise? v) + v + (resolved v))) (defn all [promises]