Fork me on GitHub
#core-async
<
2017-05-27
>
genRaiy16:05:05

quick question on alts! … the documentation says it takes one ready operation from several channels, so I’m doing something dumb in this code …. any help would be appreciated

genRaiy16:05:30

there is some incorrect interaction between the lazyseq and the alts! … so I need advice on how to make everything async

noisesmith16:05:42

use mapv if you don't want a lazy-seq

noisesmith16:05:50

and I don't see how laziness would be an advantage there

genRaiy16:05:18

godammit - you’re right

noisesmith16:05:46

you also might want to create the timeout after creating the channels

genRaiy16:05:40

hmmm … still takes the same length of time as the sync version 😞

genRaiy16:05:56

so now all the time is taken in the mapv

genRaiy16:05:06

goal is not to wait for all the ops but to schedule the ops and then read as they become ready

genRaiy16:05:52

hmmm maybe I need on-caller? = true

noisesmith16:05:02

oh - I just noticed "fetch-page" inside your block

noisesmith16:05:41

if what you need is to run fetch-page multiple times, and read results as they come in, create your chans like this: (mapv #(async/thread (fetch-page %)) usually-reliable-sites) - that will return instantly, and give you a channel for the result of each fetch-page call

genRaiy16:05:09

ah, ok that is indeed what I want!

noisesmith16:05:13

the threads will start eagerly, the chans will be ready to read as the thread finishes

genRaiy16:05:28

LOL that takes the execution from 7secs to 357ms 🙂

genRaiy16:05:47

thanks - that’s excellent

noisesmith16:05:03

async/thread is severely underrated

genRaiy16:05:26

no longer by me 🙂