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
Uh oh!
There was an error while loading. Please reload this page.
-
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_oneandthrough_async_twoare pretty much the same apart from the fact that the former is not usingbarrier.waitcall. I'm not sure why it would be needed. In either case I seem to have tomap(&:wait)my results and.waiton the Async block to give me array of results.through_async_threejust creates an empty array before the Async block and appends to it in each of the tasks and then returnresultsarray at the end outside of the Async block - is this a bad practice?Finally
through_async_fourdoesn't use the barrier altogether. It still needs tomap(&:wait)my results and.waitlike 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