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 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
Original file line number Diff line number Diff line change @@ -18,13 +18,13 @@ Here you can look a detailed [documentation][1].
1818deps.edn:
1919
2020``` clojure
21- funcool/promesa {:mvn/version " 10.0.570 " }
21+ funcool/promesa {:mvn/version " 10.0.571 " }
2222```
2323
2424Leiningen:
2525
2626``` clojure
27- [funcool/promesa " 10.0.570 " ]
27+ [funcool/promesa " 10.0.571 " ]
2828```
2929
3030## On the REPL
Original file line number Diff line number Diff line change 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]
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
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)))
Original file line number Diff line number Diff line change 382382 (pt/-untap! mx ch)))))))
383383 (recur ))
384384 (pt/-close! mx)))
385+
385386 mx)))
386387
387388(defn mult
Original file line number Diff line number Diff line change 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
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
You can’t perform that action at this time.
0 commit comments