philipbohun.com

Glojure by Example: Channel Buffering

Passing a number to chan sets the buffer size. Sends into a channel with room do not wait for a receiver. Only unbuffered and fixed buffers are supported. Dropping and sliding buffers are not.

(require '[clojure.core.async :as async])

(def messages (async/chan 2))
(async/>! messages "buffered")
(async/>! messages "channel")
(println (async/<! messages))
(println (async/<! messages))

Both sends finish before either receive.

$ glj channel-buffering.glj
buffered
channel

Next example: Channel Synchronization.