Add public channel "closed?" predicate
Description
Environment
Attachments
- 19 Jul 2015, 06:07 PM
- 19 Jun 2015, 08:59 PM
Activity
Ghadi Shayban February 12, 2016 at 8:16 PM
Echoing Brandon, I'm also unconvinced. This is a bug waiting to happen.
Brandon Bloom February 12, 2016 at 7:30 PM
Please do not add a closed? predicate to the public API. It's a race condition in 99.9% of cases. Go does not provide such a predicate and after growing accustom to CSP via both core.async and Go, I have never felt the need for it. Having the predicate would invite its use. I enjoy clojure.core's preference for omission of questionable functions and expect the same from core.async.
If somebody desperately feels the need for this predicate, ask in IRC or Slack, I'm sure somebody can help you fix the structuring of your channels/processes/etc.
Stuart Sierra July 19, 2015 at 6:07 PM
Previous patch was missing the Clojure(JVM) implementation. Fixed in new patch 0002-ASYNC-126-Add-public-channel-closed-predicate.patch.
Alejandro July 18, 2015 at 5:41 PM
The patch only adds 'closed?' to the ClojureScript version of core.async, is there a reason for not adding it to the Clojure version?
Details
Assignee
Stuart SierraStuart SierraReporter
Stuart SierraStuart SierraApproval
TriagedPatch
CodePriority
Major
Details
Details
Assignee
Reporter
Approval
Patch
Priority

Current patch file: 0002-ASYNC-126-Add-public-channel-closed-predicate.patch
Add a public function
closed?
in clojure.core.async to determine if a channel is closed without putting or taking any values.This is a trivial wrapper around
clojure.core.async.impl.protocols/closed?
There is still a race between
closed?
andclose!
. Correct code should never rely onclosed?
to check that a channel is open. Theclosed?
predicate should only be used to avoid extra work producing a value for a closed channel.Example use case
A producer process can check if a channel is
closed?
before doing the work to produce the next value.(thread (loop [] (when-not (closed? ch) (>!! ch (do-expensive-work)) (recur))))