Skip to content

Commit aa342bc

Browse files
committed
Set version to 10.0.571
1 parent 090dca2 commit aa342bc

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog #
22

3+
## Version 10.0.571
4+
5+
- Revert deprecation of `then'` and `chain'`
6+
- Add **experimental** `promesa.core/wait-all` helper
7+
8+
39
## Version 10.0.570
410

511
- Add `promesa.exec.csp/mult*` alternative multiplexer constructor

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Here you can look a detailed [documentation][1].
1818
deps.edn:
1919

2020
```clojure
21-
funcool/promesa {:mvn/version "10.0.570"}
21+
funcool/promesa {:mvn/version "10.0.571"}
2222
```
2323

2424
Leiningen:
2525

2626
```clojure
27-
[funcool/promesa "10.0.570"]
27+
[funcool/promesa "10.0.571"]
2828
```
2929

3030
## On the REPL

src/promesa/core.cljc

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@
147147
(pt/-bind (pt/-promise p) (comp pt/-promise f) executor)))
148148

149149
(defn then'
150-
{:deprecated "9.3"
151-
:no-doc true}
150+
"Chains a function `f` to be executed when the promise `p` is
151+
successfully resolved. Returns a promise that will be resolved with
152+
the return value of calling `f` with value as single argument; `f`
153+
should return a plain value, no automatic unwrapping will be
154+
performed.
155+
156+
The computation will be executed in the completion thread by
157+
default; you also can provide a custom executor."
152158
([p f]
153159
(pt/-map (pt/-promise p) f))
154160
([p f executor]
@@ -214,12 +220,13 @@
214220
"Chain variable number of functions to be executed serially using
215221
`then`."
216222
([p f] (then p f))
217-
([p f & fs] (reduce #(then %1 %2) p (cons f fs))))
223+
([p f & fs] (reduce then p (cons f fs))))
218224

219225
(defn chain'
220-
{:deprecated "9.3" :no-doc true}
226+
"Chain variable number of functions to be executed serially using
227+
`map`."
221228
([p f] (then' p f))
222-
([p f & fs] (reduce pt/-map (pt/-promise p) (cons f fs))))
229+
([p f & fs] (reduce #(map %2 %1) (pt/-promise p) (cons f fs))))
223230

224231
(defn handle
225232
"Chains a function `f` to be executed when the promise `p` is completed
@@ -361,6 +368,23 @@
361368
(c/->> (CompletableFuture/allOf (into-array CompletableFuture promises))
362369
(map (fn [_]
363370
(c/mapv pt/-extract promises)))))))
371+
372+
(defn wait-all
373+
"Given a variable number of promises, returns a promise which resolves
374+
to `nil` when all provided promises complete (rejected or resolved).
375+
376+
**EXPERIMENTAL**"
377+
[& promises]
378+
(c/let [state (atom (into #{} promises))
379+
d (deferred)]
380+
(c/run! (fn [p]
381+
(fnly (fn [_ _]
382+
(when-not (seq (swap! state disj p))
383+
(pt/-resolve! d nil)))
384+
p))
385+
promises)
386+
d))
387+
364388
(defn race
365389
[promises]
366390
#?(:cljs (.race impl/*default-promise* (into-array (c/map pt/-promise promises)))

src/promesa/exec/csp.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
(pt/-untap! mx ch)))))))
383383
(recur))
384384
(pt/-close! mx)))
385+
385386
mx)))
386387

387388
(defn mult

test/promesa/tests/core_test.cljc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@
9090
(t/deftest promise-from-nil-value
9191
#?(:cljs
9292
(t/async done
93-
(p/then (p/promise nil)
94-
(fn [v]
95-
(t/is (= v nil))
96-
(done))))
93+
(p/then' (p/promise nil)
94+
(fn [v]
95+
(t/is (= v nil))
96+
(done))))
9797
:clj
98-
@(p/then (p/promise nil)
99-
(fn [v]
100-
(t/is (= v nil))))))
98+
@(p/then' (p/promise nil)
99+
(fn [v]
100+
(t/is (= v nil))))))
101101

102102

103103
(t/deftest promise-from-factory
@@ -442,6 +442,19 @@
442442
p2 (p/chain p1 inc inc inc)]
443443
(t/is (= @p2 5)))))
444444

445+
(t/deftest chaining-using-chain'
446+
#?(:cljs
447+
(t/async done
448+
(let [p1 (promise-ok 100 2)
449+
p2 (p/chain' p1 inc inc inc)]
450+
(p/then p2 (fn [v]
451+
(t/is (= v 5))
452+
(done)))))
453+
:clj
454+
(let [p1 (promise-ok 100 2)
455+
p2 (p/chain' p1 inc inc inc)]
456+
(t/is (= @p2 5)))))
457+
445458
(t/deftest promisify
446459
#?(:cljs
447460
(t/async done

0 commit comments

Comments
 (0)