-
-
Save jjttjj/b7621c01fb3692d76652440c98b9711a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.core.async.impl.protocols :as impl] | |
'[clojure.core.async.impl.dispatch :as dispatch]) | |
;;=> nil | |
(extend-type java.util.concurrent.CompletionStage | |
impl/ReadPort | |
(take! [this handler] | |
(.whenCompleteAsync this | |
(reify | |
java.util.function.BiConsumer | |
(accept [_ result exception] | |
(.lock handler) | |
(let [good (and (impl/active? handler) | |
(impl/commit handler))] | |
(.unlock handler) | |
(when good | |
(dispatch/run #(good (or exception result)))))))) | |
nil)) | |
;;=> nil | |
(require '[clojure.core.async :as async]) | |
;;=> nil | |
(def cf1 (java.util.concurrent.CompletableFuture.)) | |
;;=> #'user/cf1 | |
(first (async/alts!! [(async/timeout 1000) cf1])) | |
;;=> nil | |
(.complete cf1 "Foo") | |
;;=> true | |
(first (async/alts!! [(async/timeout 1000) cf1])) | |
;;=> "Foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment