Share your thoughts in the 2021 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Docs by

Inside the documentation for core.async, the identifier port is used as an input to some functions/forms. Is port the same as chan? Or is it an interface or a protocol implemented by chan?

1 Answer

+1 vote
by
selected by
 
Best answer

A port is the read or write end of a chan. So you can think of most channel instances as having both a read and write port on both ends. In some cases the api may actually give you only a read or write port impl though and not a full chan.

The read and write port protocols are defined at
https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/protocols.clj#L15.

by
Thus, any function that takes "a channel" as a parameter, and uses the channel only for reading OR only for writing, could most properly call it a port?
by
Yes, that’s correct
...