(chan)
(chan buf-or-n)
(chan buf-or-n xform)
(chan buf-or-n xform ex-handler)
Creates a channel with an optional buffer, an optional transducer (like (map f),
(filter p) etc or a composition thereof), and an optional exception handler.
If buf-or-n is a number, will create and use a fixed buffer of that size. If a
transducer is supplied a buffer must be specified. ex-handler must be a
fn of one argument - if an exception occurs during transformation it will be called
with the thrown value as an argument, and any non-nil return value will be placed
in the channel.
Source
(defn
chan
"Creates a channel with an optional buffer, an optional transducer (like (map f),\n (filter p) etc or a composition thereof), and an optional exception handler.\n If buf-or-n is a number, will create and use a fixed buffer of that size. If a\n transducer is supplied a buffer must be specified. ex-handler must be a\n fn of one argument - if an exception occurs during transformation it will be called\n with the thrown value as an argument, and any non-nil return value will be placed\n in the channel."
([] (chan nil))
([buf-or-n] (chan buf-or-n nil nil))
([buf-or-n xform] (chan buf-or-n xform nil))
([buf-or-n xform ex-handler]
(let
[buf-or-n (if (= buf-or-n 0) nil buf-or-n)]
(when
xform
(assert buf-or-n "buffer must be supplied when transducer is"))
(channels/chan
(if (number? buf-or-n) (buffer buf-or-n) buf-or-n)
xform
ex-handler))))