Replies: 1 comment
-
Or maybe in other words - what woukd be recommended way to write a method that:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm testing out async-http gem where I'm trying to basically run a method that dispatches multiple HTTP requests concurrently and at the end returns parsed responses.
All good here but I'm confused about different ways in which this can be achieved and the documentation is bit sparse. It says for example
To issue multiple requests concurrently, you should use a barrier, e.g.
but doesn't elaborate why that is the case.Quick script showcasing four different ways I can achieve what I want:
through_async_one
andthrough_async_two
are pretty much the same apart from the fact that the former is not usingbarrier.wait
call. I'm not sure why it would be needed. In either case I seem to have tomap(&:wait)
my results and.wait
on the Async block to give me array of results.through_async_three
just creates an empty array before the Async block and appends to it in each of the tasks and then returnresults
array at the end outside of the Async block - is this a bad practice?Finally
through_async_four
doesn't use the barrier altogether. It still needs tomap(&:wait)
my results and.wait
like the first two but the end result is seemingly the same.Is there a specific difference between all those approaches? Is there a "better" way to do this?
Beta Was this translation helpful? Give feedback.
All reactions