From 6f9144267f483b6f62fff1e66bab5638fda2625e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 19 Aug 2024 20:31:27 +0200 Subject: [PATCH] Don't use use polimorphic coersion on macro return values --- src/promesa/core.cljc | 14 +++++++------- src/promesa/impl.cljc | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/promesa/core.cljc b/src/promesa/core.cljc index a726cf0..9b2a9c1 100644 --- a/src/promesa/core.cljc +++ b/src/promesa/core.cljc @@ -552,10 +552,10 @@ [& exprs] (condp = (count exprs) 0 `(impl/resolved nil) - 1 `(pt/-promise ~(first exprs)) + 1 `(impl/coerce ~(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]