core-async

Ivan Koz 2019-04-29T14:02:27.104600Z

Is that possible to enclose >! <! into a function, and use that function inside a go block?

Ivan Koz 2019-04-29T14:04:00.104900Z

most likely not, because function is a black box for state machine compiler, can somebody confirm?

alexmiller 2019-04-29T14:06:28.105300Z

no, it's not possible

alexmiller 2019-04-29T14:06:33.105500Z

for that reason

alexmiller 2019-04-29T14:06:50.105900Z

the parking calls need to be in the lexical scope of the go

Ivan Koz 2019-04-29T14:06:56.106Z

ty

Ivan Koz 2019-04-29T15:48:17.107600Z

go block returns a channel, is that channel closed already? How to make multiple go blocks work with merge.

Ivan Koz 2019-04-29T15:50:05.108900Z

at the end i want to group result of multiple concurrent tasks into a vector, so i was thinking of into merge few go's

bertofer 2019-04-29T15:50:23.109100Z

The go block returns a channel that will emit the value returned by the body and then close, afaik

bertofer 2019-04-29T15:51:13.110400Z

To do that, have a look at core.async/map, it applies f to the values read from the channels passed, to get a vector

bertofer 2019-04-29T15:51:34.110900Z

(a/map vector go-block-chans-coll)

bertofer 2019-04-29T15:52:10.111400Z

applies the function vector to all the values read, 1 value per channel, and puts into a vector

Ivan Koz 2019-04-29T15:56:04.112200Z

yeah will do, surprised that go doesn't close channel after value was put into it

(&lt;!! (async/map vector [(async/go 1)
                        (async/go 2)
                        (async/go 3)]))

đź‘Ť 1
bertofer 2019-04-29T15:57:22.112900Z

Doesn’t? I thought it does after putting the value

Ivan Koz 2019-04-29T15:57:59.113300Z

strange why merge doesn't work properly then?

Ivan Koz 2019-04-29T15:58:14.113600Z

(&lt;!! (async/merge [(async/go 1)
                   (async/go 2)
                   (async/go 3)]))
=&gt; 2

bertofer 2019-04-29T15:58:51.114300Z

By merge you will have a channel that combines all the values from the others, so you will read one by one the results of the tasks as they come in

bertofer 2019-04-29T15:59:03.114700Z

with map, it waits till all of them emit a value to execute f

Ivan Koz 2019-04-29T16:00:10.115500Z

ok i see

Ivan Koz 2019-04-29T16:04:45.116300Z

looks like in case of multiple go's merge will work aswell, it wasn't working at first, i was thinking go channels wasn't closed until you take a value

(&lt;!! (async/map vector 
                [(async/go 1)
                 (async/go 2)
                 (async/go 3)]))
=&gt; [1 2 3]
(&lt;!! (async/into [] (async/merge [(async/go 1)
                                  (async/go 2)
                                  (async/go 3)])))
=&gt; [1 2 3]

2019-04-29T16:06:12.116800Z

merge is not ordered