Fork me on GitHub
#core-async
<
2018-03-13
>
jimbob20:03:12

What is the best way to deal with IO in a worker in an async manner? for example: I want a long running worker to poll sqs for messages(IO) and do a bunch of things with these messages. Should I then use a go block for all of it and make an additional thread (async/thread) for all IO?

noisesmith20:03:33

definitely use thread for io, and read from the channel that thread returns

noisesmith20:03:45

(if you need io inside a core.async context)

jimbob21:03:49

but why? wouldn’t the io just take up one thread? wouldnt the behavior be the same?

jimbob21:03:20

say 8 threads with a go block, we are “parked” on one thread trying to read from SQS say. so then the threads get released into the pool until we get the messages from sqs and everything resumes as normal. same thing with using a thread in a go block right? except instead we spawn an additional thread, but the go block is still parked on getting a results from the thread channel, so the result is the same, right?

jimbob21:03:55

is the difference the type of threads? is that all it is?

jimbob21:03:39

ah wait i see, when we try to read from SQS in a go-block we aren’t releasing the other threads into the pool since its not an async take

noisesmith21:03:40

thread returns a channel, parking on a channel doesn't block

noisesmith21:03:56

right - if you read from sqs in the go block itself you do block

jimbob21:03:19

gotcha, so an async take from a thread operation in a go block will release threads, but otherwise if its not an async operation it will just block. excellent. thanks!

jimbob21:03:34

now to determine whether or not i actually need to use a go block. heh