(defn
do-alts
"returns derefable [val port] if immediate, nil if enqueued"
[fret ports opts]
(let
[flag
(alt-flag)
n
(count ports)
idxs
(random-array n)
priority
(:priority opts)
ret
(loop
[i 0]
(when
(< i n)
(let
[idx
(if priority i (aget idxs i))
port
(nth ports idx)
wport
(when (vector? port) (port 0))
vbox
(if
wport
(let
[val (port 1)]
(impl/put!
wport
val
(alt-handler
flag
(fn* [p1__18541#] (fret [p1__18541# wport])))))
(impl/take!
port
(alt-handler
flag
(fn* [p1__18542#] (fret [p1__18542# port])))))]
(if
vbox
(channels/box [@vbox (or wport port)])
(recur (inc i))))))]
(or
ret
(when
(contains? opts :default)
(when-let
[got (and (impl/active? flag) (impl/commit flag))]
(channels/box [(:default opts) :default]))))))