<< Back to previous view

[ASYNC-135] alt! with a closed channel will still return results from the closed channel Created: 27/Jul/15  Updated: 27/Jul/15

Status: Open
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Daniel Compton Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I'm not sure if this is a documentation bug, or an implementation bug, but alt! will always return nil from chan1 in the following code.

(let [chan1 (async/chan 10)
      chan2 (async/chan 10)]
  (async/close! chan1)
  (async/>!! chan2 "run")
  (async/go (async/alt! :priority true

               chan1 ([val] (println "chan1" val))

               chan2 ([val] (println "chan2" val)))))
;; => chan1 nil

The intent of my code was to alt! over the two channels, preferring chan1, but running chan2 if chan1 has nothing to take. However changing this would interfere with using timeout channels in an alt!, so it seems like documenting this might be the best fix?






[ASYNC-134] async/alts!! with an empty vector throws ArrayIndexOutOfBoundsException Created: 27/Jul/15  Updated: 28/Jul/15

Status: Open
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Daniel Compton Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I'm not sure if this is intended, but this code throws an exception.

(async/alts!! [])
;; => ArrayIndexOutOfBoundsException 1  clojure.core.async/random-array (async.clj:182)

Is this desired behaviour, or is there another way we could represent that this collection is empty? I'm thinking of the pattern where we take from any channel, and recur with that channel removed from the collection until the collection is empty. Perhaps this usage should be discouraged. If it should be discouraged, should it be documented in the docstring?



 Comments   
Comment by Alex Miller [ 28/Jul/15 9:08 AM ]

What would you expect this to do?

Comment by Daniel Compton [ 28/Jul/15 5:20 PM ]

You could return [nil nil]? That's not great either though. Documentation is probably a better fix.





Generated at Wed Jul 29 21:06:16 CDT 2015 using JIRA 4.4#649-r158309.