Fork me on GitHub

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?


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


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


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


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?


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


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


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


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


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!


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