Fork me on GitHub
#core-async
<
2021-07-10
>
Franco Gasperino21:07:27

This may be more of a macro expansion question than async, but i'm noodling on how to express channels WRT alt!!

; Works as expected
  (let [c1 (async/chan 1)
        c2 (async/chan 1)
        t (async/timeout 1000)]
    (async/>!! c2 :message-2)
    (async/alt!!
     t :timed-out
     [c1 c2] ([v p] (str "Read " v " from " p))
     :default :no-action))

; fails. the vector of ports for alt!! is pre-bound.
    (let [c1 (async/chan 1)
          c2 (async/chan 1)
          chans [c1 c2]
          t (async/timeout 1000)]
      (async/>!! c2 :message-2)
      (async/alt!!
        t :timed-out
        chans ([v p] (str "Read " v " from " p))
        :default :no-action))

Franco Gasperino21:07:30

in my case, i have a generic operation function that takes 2 optional maps - read operations and write operations. I would like to be able to concat these together and provide them as vector to alt!! but am hitting the above snag.

phronmophobic21:07:25

What's the error that you're getting? If you can't do the top version, then you may have to use alts!! and manually react to which channel operation succeeded

Franco Gasperino23:07:53

Thank you. alts!! resolved it