Is that possible to enclose >! <! into a function, and use that function inside a go block?
most likely not, because function is a black box for state machine compiler, can somebody confirm?
no, it's not possible
for that reason
the parking calls need to be in the lexical scope of the go
ty
go block returns a channel, is that channel closed already? How to make multiple go blocks work with merge.
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
The go block returns a channel that will emit the value returned by the body and then close, afaik
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
(a/map vector go-block-chans-coll)
applies the function vector to all the values read, 1 value per channel, and puts into a vector
yeah will do, surprised that go
doesn't close channel after value was put into it
(<!! (async/map vector [(async/go 1)
(async/go 2)
(async/go 3)]))
Doesn’t? I thought it does after putting the value
strange why merge doesn't work properly then?
(<!! (async/merge [(async/go 1)
(async/go 2)
(async/go 3)]))
=> 2
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
with map, it waits till all of them emit a value to execute f
ok i see
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
(<!! (async/map vector
[(async/go 1)
(async/go 2)
(async/go 3)]))
=> [1 2 3]
(<!! (async/into [] (async/merge [(async/go 1)
(async/go 2)
(async/go 3)])))
=> [1 2 3]
merge is not ordered