core-async

mpenet 2019-12-20T15:40:36.014300Z

just curious: why isn't a promise-chan auto-closed when it holds a "realized" value

mpenet 2019-12-20T15:46:20.016300Z

since it will return the delivered value on takes just the same

mpenet 2019-12-20T15:51:13.017Z

> * 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

mpenet 2019-12-20T15:51:31.017300Z

I guess it's to allow this nil broadcasting

mpenet 2019-12-20T15:51:52.017600Z

ah wait no, it's only if no put happened

mpenet 2019-12-20T15:54:22.018400Z

in my case in particular I was surprised by the put! return value on undelivered/already delivered/closed promise-chan

mpenet 2019-12-20T15:57:16.019600Z

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

alexmiller 2019-12-20T15:58:34.021200Z

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.

fmjrey 2019-12-20T16:03:26.024100Z

The question is more about puting a value to a promise-chan that already has a value

mpenet 2019-12-20T16:03:32.024300Z

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

mpenet 2019-12-20T16:04:14.024900Z

@fmjrey I am fine with that, it's for convenience and a way to know if it's already closed

mpenet 2019-12-20T16:04:47.025300Z

same as when you put into a normal closed chan, it will just drop it and return nil

fmjrey 2019-12-20T16:14:15.025900Z

For the record: https://clojure.atlassian.net/browse/ASYNC-103

mpenet 2019-12-20T16:15:27.026200Z

that's what I quoted before

fmjrey 2019-12-20T16:16:03.026600Z

I know, just making it easier for whoever else is following

mpenet 2019-12-20T16:28:58.027300Z

it's possible to golf around having autoclosing promise-chan via an xform

mpenet 2019-12-20T16:29:03.027500Z

but yuk 🙂

mpenet 2019-12-20T16:33:00.027900Z

(async/promise-chan (take 1))

mpenet 2019-12-20T16:34:10.028400Z

(-> (doto (async/promise-chan (take 1))
      (async/>!! :foo))
    (async/put! :bar))
 => false