heterogeneous async/alts?

10 views
Skip to first unread message

Peter Fraenkel

unread,
Jan 22, 2015, 1:55:22 PM1/22/15
to clojure-c...@googlegroups.com
I was hoping I could call alts! on an HVec of channels, and then match on the return value, like this:
(defn foo []
  (t/let [c-in :- (ta/Chan t/Int) (chan)
          c-in2 :- (ta/Chan t/Int) (chan)
          c-in3 :- (ta/Chan t/Str) (chan)
          tt    :- (ta/Chan (t/Val nil)) (timeout 1000)
          ]
    (ta/go-loop []
      (let [[c v] (async/alts! [c-in c-in2 c-in3 tt])]
        (case c
         c-in    (println v "is an integer")
         c-in2   (println v "is an integer")
         c-in3   (println v "is a string")
         tt      (println "Hurry up.")))
     )
  c-in))
This only type-checks if I comment out c-in3 and tt.  Ideally, it would have returned a union type of the possible return values, which would be winnowed down based on the case match.  Is this supposed to be possible?

Reply all
Reply to author
Forward
0 new messages