Skip to content

Commit

Permalink
Remove some wrapping logic from -bind impl.
Browse files Browse the repository at this point in the history
Now is fully compliant.
  • Loading branch information
niwinz committed Mar 17, 2016
1 parent a97ae98 commit 6580de1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
11 changes: 3 additions & 8 deletions src/promesa/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
(-pending? [it]
(.isPending it))))


#?(:clj
(extend-type CompletionStage
ICancellable
Expand All @@ -202,19 +203,13 @@
(-map [it cb]
(.thenApplyAsync it (reify Function
(apply [_ v]
(let [result (cb v)]
result)))
(cb v)))
+executor+))

(-bind [it cb]
(.thenComposeAsync it (reify Function
(apply [_ v]
(let [result (cb v)]
(if-not (instance? CompletionStage result)
(let [p (CompletableFuture.)]
(.complete p result)
p)
result))))
(cb v)))
+executor+))

(-catch [it cb]
Expand Down
13 changes: 2 additions & 11 deletions test/promesa/core_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,6 @@
;; Cats Integration Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(t/deftest bind-with-ifn
(let [p (-> (p/promise {:x ::value})
(m/>>= :x))]
#?(:cljs
(t/async done
(p/then p (fn [x]
(t/is (= x ::value))
(done))))
:clj
(t/is (= @p ::value)))))

#?(:cljs
(t/deftest extract-from-rejected-promise
(let [p1 (p/rejected 42)]
Expand All @@ -329,12 +318,14 @@
#?(:cljs
(t/async done
(let [p1 (future-ok 200 2)
inc #(p/resolved (inc %))
p2 (m/>>= p1 inc inc inc)]
(p/then p2 (fn [v]
(t/is (= v 5))
(done)))))
:clj
(let [p1 (future-ok 200 2)
inc #(p/resolved (inc %))
p2 (m/>>= p1 inc inc inc)]
(t/is (= @p2 5)))))

Expand Down

0 comments on commit 6580de1

Please sign in to comment.