core.async

Add chan? or channel? function to identify a channel

Details

  • Type: Enhancement Enhancement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

There are cases where one may be handed a value which could possibly be a channel. It would be nice to have a function which returns true if a value is a channel. This can currently be done from user code but requires reaching into the clojure.core.async.impl.channels namespace and depending on an implementation detail.

(defn channel? [c]
(satisfies? channels/MMC c))

Activity

Brenton Ashworth made changes -
Field Original Value New Value
Assignee Rich Hickey [ richhickey ]
Hide
Hugo Duncan added a comment -

I ran into the need for this when writing a schema to validate input arguments.

Show
Hugo Duncan added a comment - I ran into the need for this when writing a schema to validate input arguments.
Hide
Timothy Baldridge added a comment -

We're rejecting this feature for now. If you need to check if an object implements the correct interfaces, feel free to dive into clojure.core.async.impl.protocols and check for satisfies? against ReadPort and WritePort. Not only do these allow you to accept ReadPorts that aren't channels, but it also keeps the main interface from getting cluttered.

At least this was the argument Rich proposed last time we talked. If this won't work, feel free to submit a new ticket or start a clojure-dev mailing list thread.

Show
Timothy Baldridge added a comment - We're rejecting this feature for now. If you need to check if an object implements the correct interfaces, feel free to dive into clojure.core.async.impl.protocols and check for satisfies? against ReadPort and WritePort. Not only do these allow you to accept ReadPorts that aren't channels, but it also keeps the main interface from getting cluttered. At least this was the argument Rich proposed last time we talked. If this won't work, feel free to submit a new ticket or start a clojure-dev mailing list thread.
Timothy Baldridge made changes -
Resolution Declined [ 2 ]
Assignee Timothy Baldridge [ halgari ]
Status Open [ 1 ] Resolved [ 5 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: