Skip to content

Commit 045a29d

Browse files
committed
update cats.labs.promise for changes in promesa
as much as we’re going all the way from 1.9.0 to 5.1.0 there’s only two real changes needed: 1. Promesa now allows for a configurable promise type. I’ve used the same “define a fn to extend the implementation class, call it on the default class” pattern as used in `promesa.impl` to add implementations of the `Contextual` and `Extract` protocols. 2. The protocol fn `-catch` has been removed, replaced by `-mapErr` and `-thenErr`. I’ve replaced it’s use with `-thenErr` (as promise flattening in an error handler seems more appropriate than not.)
1 parent e5bf1e7 commit 045a29d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/cats/labs/promise.cljc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@
44
[cats.context :as mc]
55
[cats.protocols :as mp]
66
[promesa.core :as p]
7+
[promesa.impl :as pi]
78
[promesa.protocols :as pp])
89
#?(:clj
910
(:import java.util.concurrent.CompletableFuture)))
1011

1112
(declare context)
1213

13-
(extend-type #?(:cljs p/Promise :clj CompletableFuture)
14-
mp/Contextual
15-
(-get-context [_] context)
14+
#?(:cljs
15+
(defn extend-promise!
16+
[t]
17+
(extend-type t
18+
mp/Contextual
19+
(-get-context [_] context)
1620

17-
mp/Extract
18-
(-extract [it]
19-
(pp/-extract it)))
21+
mp/Extract
22+
(-extract [it]
23+
(pp/-extract it)))))
24+
25+
#?(:cljs (extend-promise! pi/*default-promise*))
26+
27+
#?(:clj
28+
(extend-type CompletableFuture
29+
mp/Contextual
30+
(-get-context [_] context)
31+
32+
mp/Extract
33+
(-extract [it]
34+
(pp/-extract it))))
2035

2136
(def ^:no-doc context
2237
(reify
@@ -29,7 +44,7 @@
2944
(-bimap [_ err succ mv]
3045
(-> mv
3146
(pp/-map succ)
32-
(pp/-catch err)))
47+
(pp/-thenErr err)))
3348

3449
mp/Monad
3550
(-mreturn [_ v]

0 commit comments

Comments
 (0)