Fork me on GitHub
#core-async
<
2021-12-16
>
dpsutton20:12:58

sanity check, (a/to-chan! [value]) is exactly equivalent to (go value) right?

Alex Miller (Clojure team)20:12:10

the latter will create and capture bindings and launch a go block on the go thread pool

Alex Miller (Clojure team)20:12:58

I mean, I guess they are very similar

dpsutton20:12:08

i see. i was thinking there was an easier way to end up with a channel with a single value on it but you’re right go does quite a bit of state machine more than just channel with value

Alex Miller (Clojure team)20:12:10

I think to-chan! will close the returned channel and the go one will not?

Alex Miller (Clojure team)20:12:26

well to-chan! calls onto-chan! that uses a go loop, so they will both do that

Alex Miller (Clojure team)20:12:29

I guess they both close

Alex Miller (Clojure team)20:12:41

functionally, they will end up being pretty close

dpsutton20:12:24

i see. thanks alex. the to-chan! felt heavier to me at first blush but it seems clearly not. thanks for reasoning that out for me

hiredman21:12:51

I would do something like (doto (async/chan 1) (async/put! value) (async/close!))

Ben Sless21:12:11

Is that the core.async version of monadic pure?

hiredman21:12:03

if you insist on using channels as one shot things like java futures or javascript promises

hiredman21:12:07

if you use channels as queues that multiple values flow through, it doesn't line up with the way futures/promises are interpreted as monads

Ben Sless21:12:27

Mostly trying to check my understanding

Ben Sless21:12:40

But channels implementing a "flow" and a "task" at the same time makes it ambiguous. Should a promise channel be used here?

hiredman21:12:24

if you want

hiredman21:12:53

if you are trying to emulate to-chan! or go without spinning up a go loop, then not using a promise-chan does that

Alex Miller (Clojure team)21:12:58

Now to-chan!! is a lot lighter for the case of a single value