Back

<!! (clj)

(source)

(<!! port)
takes a val from port. Will return nil if closed. Will block if nothing is available. Not intended for use in direct or transitive calls from (go ...) blocks. Use the clojure.core.async.go-checking flag to detect invalid use (see namespace docs).

Examples

core.async
;; The clojure.core.async namespace contains the public API.
(require '[clojure.core.async :as async :refer :all])

;; In ordinary threads, we use `>!!` (blocking put) and `<!!`
;; (blocking take) to communicate via channels.

(let [c (chan 10)]
  (>!! c "hello")
  (assert (= "hello" (<!! c)))
  (close! c))

(let [c (chan)]
  (thread (>!! c "hello"))
  (assert (= "hello" (<!! c)))
  (close! c))

;; Here we convert our prior channel example to use go blocks:
(let [c (chan)]
  (go (>! c "hello"))
  (assert (= "hello" (<!! (go (<! c)))))
  (close! c))

(let [t (timeout 100)
      begin (System/currentTimeMillis)]
  (<!! t)
  (println "Waited" (- (System/currentTimeMillis) begin)))
core.async
(require '[clojure.core.async :as async :refer [<! >! <!! >!! timeout chan alt! alts!! go]])

(defn fan-out [in cs-or-n]
  (let [cs (if (number? cs-or-n)
             (repeatedly cs-or-n chan)
             cs-or-n)]
   (future (while true
             (let [x (<!! in)
                   outs (map #(vector % x) cs)]
               (alts!! outs))))
   cs))

(let [cout (chan)
      cin (fan-in (fan-out cout (repeatedly 3 chan)))]
  (dotimes [n 10]
    (>!! cout n)
    (prn (<!! cin))))
core.async
(require '[clojure.core.async :as async :refer [<!! >!! timeout chan alt!!]])

(defn fake-search [kind]
  (fn [c query]
    (future
     (<!! (timeout (rand-int 100)))
     (>!! c [kind query]))))

(defn google [query]
  (let [c (chan)
        t (timeout 80)]
    (future (>!! c (<!! (fastest query web1 web2))))
    (future (>!! c (<!! (fastest query image1 image2))))
    (future (>!! c (<!! (fastest query video1 video2))))
    (loop [i 0 ret []]
      (if (= i 3)
        ret
        (recur (inc i) (conj ret (alt!! [c t] ([v] v))))))))
core.async
(require '[clojure.core.async :as async :refer [<! >! <!! timeout chan alt! go]])

(<!! (google "clojure"))
clojure/core.async
;; The clojure.core.async namespace contains the public API.
(require '[clojure.core.async :as async :refer :all])

;; In ordinary threads, we use `>!!` (blocking put) and `<!!`
;; (blocking take) to communicate via channels.

(let [c (chan 10)]
  (>!! c "hello")
  (assert (= "hello" (<!! c)))
  (close! c))

(let [c (chan)]
  (thread (>!! c "hello"))
  (assert (= "hello" (<!! c)))
  (close! c))

;; Here we convert our prior channel example to use go blocks:
(let [c (chan)]
  (go (>! c "hello"))
  (assert (= "hello" (<!! (go (<! c)))))
  (close! c))

(let [t (timeout 100)
      begin (System/currentTimeMillis)]
  (<!! t)
  (println "Waited" (- (System/currentTimeMillis) begin)))
clj-commons/manifold
(ns manifold.stream.async
  {:no-doc true}
  (:require
    [manifold.deferred :as d]
    [clojure.core.async :as a]
    [manifold.stream
     [graph :as g]
     [core :as s]]
    [manifold
     [executor :as executor]
     [utils :as utils]])
  (:import
    [java.util.concurrent.atomic
     AtomicReference]))

      (let [x (a/<!! ch)]
        (if (nil? x)
          (do
            (.markDrained this)
            default-val)
          x))
cognitect-labs/aws-api
(ns s3-examples
  (:require [clojure.core.async :as a]
            [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [clojure.java.io :as io]
            [clojure.repl :as repl]
            [cognitect.aws.client.api :as aws]))

  (a/<!! c)

  ;; supply your own channel
  (let [ch (a/chan)]
    (aws/invoke-async s3 {:op :ListBuckets
                          :ch ch})
    (a/<!! ch))
epiccastle/spire
(ns spire.output.events
  (:require [spire.output.core :as output]
            [puget.printer :as puget]
            [clojure.core.async :refer [<!! put! go chan thread]]))

(defmethod output/print-thread :events [_]
  (thread
    (loop []
      (puget/cprint (<!! prn-chan))
      (recur))))
unclebob/more-speech
(ns more-speech.websocket-relay-spec
  (:require [speclj.core :refer :all]
            [clojure.core.async :as async]
            [more-speech
             [relay :as relay]
             [websocket-relay :as ws-relay]]))

  (it "can send and receive"
    (pending "be nice to relay.damus.io")
    (let [chan (async/chan)
          recv-f (fn [relay msg] (async/>!! chan [relay msg]))
          relay (ws-relay/make "wss://relay.damus.io" recv-f)
          relay-open (relay/open relay)
          _ (relay/send relay-open ["test"])
          f-reply (future (async/<!! chan))
          [relay-r reply] (deref f-reply 1000 :timeout)
          _ (relay/close relay-open)]
      (should= relay relay-r )
      (should= ["NOTICE" "could not parse command"] reply)))
  )