core.typed

clojure.core.async/alts!! annotation does not account for returning nil values

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    clojure.core.typed 0.2.13

Description

The current annotation for clojure.core.async/alts can be seen here: https://github.com/clojure/core.typed/blob/2e4f691d989d7b063d2e43f6f3d3395c0aeb16b5/src/main/clojure/clojure/core/typed/async.clj#L136

I believe it needs to be updated to account for returning a nil value if the channel is closed, or if the operation is a put, given the doc for alts!/alts!!:

clojure.core.async/alts!
([ports & {:as opts}])
Completes at most one of several channel operations. Must be called
inside a (go ...) block. ports is a vector of channel endpoints, which
can be either a channel to take from or a vector of
[channel-to-put-to val-to-put], in any combination. Takes will be
made as if by <!, and puts will be made as if by >!. Unless
the :priority option is true, if more than one port operation is
ready a non-deterministic choice will be made. If no operation is
ready and a :default value is supplied, [default-val :default] will
be returned, otherwise alts! will park until the first operation to
become ready completes. Returns [val port] of the completed
operation, where val is the value taken for takes, and nil for puts.

opts are passed as :key val ... Supported options:

:default val - the value to use if none of the operations are immediately ready
:priority true - (default nil) when true, the operations will be tried in order.

Note: there is no guarantee that the port exps or val exprs will be
used, nor in what order should they be, so they should not be
depended upon for side effects.

So presumably the annotation should be something more like this: https://gist.github.com/mybuddymichael/b209294b52171c875a01

Activity

Ambrose Bonnaire-Sergeant made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Ambrose Bonnaire-Sergeant made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: