File tree Expand file tree Collapse file tree 5 files changed +58
-14
lines changed Expand file tree Collapse file tree 5 files changed +58
-14
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog #
2
2
3
+ ## Version 10.0.571
4
+
5
+ - Revert deprecation of ` then' ` and ` chain' `
6
+ - Add ** experimental** ` promesa.core/wait-all ` helper
7
+
8
+
3
9
## Version 10.0.570
4
10
5
11
- Add ` promesa.exec.csp/mult* ` alternative multiplexer constructor
Original file line number Diff line number Diff line change @@ -18,13 +18,13 @@ Here you can look a detailed [documentation][1].
18
18
deps.edn:
19
19
20
20
``` clojure
21
- funcool/promesa {:mvn/version " 10.0.570 " }
21
+ funcool/promesa {:mvn/version " 10.0.571 " }
22
22
```
23
23
24
24
Leiningen:
25
25
26
26
``` clojure
27
- [funcool/promesa " 10.0.570 " ]
27
+ [funcool/promesa " 10.0.571 " ]
28
28
```
29
29
30
30
## On the REPL
Original file line number Diff line number Diff line change 147
147
(pt/-bind (pt/-promise p) (comp pt/-promise f) executor)))
148
148
149
149
(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."
152
158
([p f]
153
159
(pt/-map (pt/-promise p) f))
154
160
([p f executor]
214
220
" Chain variable number of functions to be executed serially using
215
221
`then`."
216
222
([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))))
218
224
219
225
(defn chain '
220
- {:deprecated " 9.3" :no-doc true }
226
+ " Chain variable number of functions to be executed serially using
227
+ `map`."
221
228
([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))))
223
230
224
231
(defn handle
225
232
" Chains a function `f` to be executed when the promise `p` is completed
361
368
(c/->> (CompletableFuture/allOf (into-array CompletableFuture promises))
362
369
(map (fn [_]
363
370
(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
+
364
388
(defn race
365
389
[promises]
366
390
#? (:cljs (.race impl/*default-promise* (into-array (c/map pt/-promise promises)))
Original file line number Diff line number Diff line change 382
382
(pt/-untap! mx ch)))))))
383
383
(recur ))
384
384
(pt/-close! mx)))
385
+
385
386
mx)))
386
387
387
388
(defn mult
Original file line number Diff line number Diff line change 90
90
(t/deftest promise-from-nil-value
91
91
#? (:cljs
92
92
(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 ))))
97
97
: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 ))))))
101
101
102
102
103
103
(t/deftest promise-from-factory
442
442
p2 (p/chain p1 inc inc inc)]
443
443
(t/is (= @p2 5 )))))
444
444
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
+
445
458
(t/deftest promisify
446
459
#? (:cljs
447
460
(t/async done
You can’t perform that action at this time.
0 commit comments