Back
await (clj)
(source)function
(await & agents)
Blocks the current thread (indefinitely!) until all actions
dispatched thus far, from this thread or agent, to the agent(s) have
occurred. Will block on failed agents. Will never return if
a failed agent is restarted with :clear-actions true or shutdown-agents was called.
Examples
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
#?@(:cljs [] :default [
cc/get-thread-bindings [:-> (t/Map t/AnyVar t/Any)]
cc/bound-fn*
(t/All [r b :..]
[[b :.. b :-> r] :-> [b :.. b :-> r]])
cc/find-var
[t/Sym :-> (t/Nilable t/AnyVar)]
cc/agent
(t/All [x] [x & :optional {:validator (t/Nilable [x :-> t/Any]) :meta t/Any
:error-handler (t/Nilable [(t/Agent x) Throwable :-> t/Any])
:error-mode (t/U ':continue ':fail)}
:-> (t/Agent x)])
cc/set-agent-send-executor! [java.util.concurrent.ExecutorService :-> t/Any]
cc/set-agent-send-off-executor! [java.util.concurrent.ExecutorService :-> t/Any]
cc/send-via (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/send (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/send-off (t/All [x b :..] [(t/Agent x) [x b :.. b :-> x] b :.. b :-> (t/Agent x)])
cc/await [t/AnyAgent :* :-> nil]
cc/await-for [t/AnyInteger t/AnyAgent :* :-> t/Bool]
cc/await1 (t/All [[a :< t/AnyAgent]] [a :-> (t/Nilable a)])
cc/release-pending-sends [:-> t/AnyInteger]
])
metosin/sieppari
(ns sieppari.async.core-async
(:require [sieppari.async :as sa]
[sieppari.util :refer [exception?]]
[clojure.core.async :as cca
#?@(:clj [:refer [go <! <!!]]
:cljs [:refer-macros [go]])]))
(extend-protocol sa/AsyncContext
#?(:clj clojure.core.async.impl.protocols.Channel
:cljs cljs.core.async.impl.channels/ManyToManyChannel)
(async? [_] true)
(continue [c f] (go (f (cca/<! c))))
(catch [c f] (go (let [c (cca/<! c)]
(if (exception? c) (f c) c))))
#?(:clj (await [c] (<!! c))))
wilkerlucio/wsscode-async
(ns com.wsscode.async.processing-test
(:require [clojure.core.async :as async]
[clojure.test :refer [deftest is are run-tests testing]]
[#?(:clj com.wsscode.async.async-clj
:cljs com.wsscode.async.async-cljs)
:refer [go-promise <! <? deftest-async]]
[com.wsscode.async.processing :as wap]))
(deftest-async id-callbacks-test
(let [msg {::wap/request-id (wap/random-request-id)}
request (wap/await! msg)]
(wap/capture-response! (wap/reply-message msg "value"))
(is (= (<? request) "value")))
(testing "don't try to reply a reply message"
(let [msg {::wap/request-id (wap/random-request-id)
::wap/request-response "Answered"}
request (wap/await! msg)]
(is (nil? request)))))
Datomic/client-examples
(require '[datomic.client :as client]
'[clojure.core.async :refer [<!!]])
;; create, awaiting point-in-time-value
(def db-after-create
(-> (client/transact conn
{:tx-data [[:db/add "entity" :crud/name "Hello world"]]})
<!! :db-after))
mauricioszabo/repl-tooling
(ns repl-tooling.editor-integration.connection-test
(:require [clojure.test :refer [testing]]
[check.core :refer [check]]
[check.async-old :as a]
[clojure.core.async :as async]
[repl-tooling.editor-integration.connection :as connection]
[repl-tooling.editor-helpers :as editor-helpers]
[repl-tooling.eval :as eval]))
(testing "capturing result"
(-> repls a/await! :clj/repl (eval/evaluate "(/ 10 2)" {} identity))
(check (a/await! result) => 5))
(testing "evaluating request-response with invalid EDN"
(let [res (async/promise-chan)]
(-> repls a/await! :clj/repl (eval/evaluate "{(keyword \"foo bar\") 10}" {}
#(async/put! res (editor-helpers/parse-result %))))
(check (:result (a/await! res)) => {(keyword "foo bar") 10}))
(let [res (async/promise-chan)]
(-> repls a/await! :clj/repl (eval/evaluate "{(symbol \"foo bar\") 10}" {}
#(async/put! res (editor-helpers/parse-result %))))
(check (:result (a/await! res)) => {(symbol "foo bar") 10})))
(testing "capturing stdout"
(-> repls a/await! :clj/repl (eval/evaluate '(prn :foo) {} identity))
(check (a/await! stdout) => ":foo\n"))
(testing "capturing stderr"
(-> repls a/await! :clj/repl (eval/evaluate "(binding [*out* *err*] (prn :bar))" {} identity))
(check (a/await! stderr) => ":bar"))
(testing "capturing error"
(-> repls a/await! :clj/repl (eval/evaluate "(/ 10 0)" {} identity))
(check (a/await! error) => map?))
(testing "disconnecting"
(connection/disconnect!)
(check (a/await! disconnect) => :DONE))))
(a/def-async-test "Batches of commands" {:teardown (connection/disconnect!)}
(let [repls (async/promise-chan)
stdout (async/chan 60000)]
(. (connection/connect-unrepl! "localhost" 2233
#(async/put! stdout %)
#()
#()
#())
then #(async/put! repls %))
(-> repls a/await! :clj/repl (eval/evaluate "(doseq [n (range 2000)] (prn n))" {} identity))
(doseq [n (range 2000)]
(check (a/await! stdout) => (str n "\n")))))