just curious: why isn't a promise-chan auto-closed when it holds a "realized" value
since it will return the delivered value on takes just the same
> * After a put, all pending takes are notified, and any subsequent takes return the put value immediately > * After a close (and no put), all pending takes are notified with nil, and any subsequent takes return nil immediately
I guess it's to allow this nil broadcasting
ah wait no, it's only if no put happened
in my case in particular I was surprised by the put! return value on undelivered/already delivered/closed promise-chan
In short:
(-> (doto (async/promise-chan)
(async/>!! :foo)
(async/close!))
(async/put! :bar))
false
vs
(-> (doto (async/promise-chan)
(async/>!! :foo))
(async/put! :bar))
true
promise-chans are inherently multi listener (as all channels). there are two cases - a value is delivered, or the chan is closed. All pending listeners receive either the value, or nil.
The question is more about puting a value to a promise-chan that already has a value
right now there's a 3rd case, the value is delivered and the chan is close!d. I get why we have close! for an "empty" promise-chan, it's just a bit weird when it's already realized
@fmjrey I am fine with that, it's for convenience and a way to know if it's already closed
same as when you put into a normal closed chan, it will just drop it and return nil
For the record: https://clojure.atlassian.net/browse/ASYNC-103
that's what I quoted before
I know, just making it easier for whoever else is following
it's possible to golf around having autoclosing promise-chan via an xform
but yuk 🙂
(async/promise-chan (take 1))
(-> (doto (async/promise-chan (take 1))
(async/>!! :foo))
(async/put! :bar))
=> false