• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: HTTP fetch info IN ORDER and add to array in the order specified

Resolved: HTTP fetch info IN ORDER and add to array in the order specified

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have tried it all. I want to fetch from my server some data in a loop, and add the ressponses in an array in the order I run the for loop.
I am thinking the answer is in recursion, but tried it several times and failed.
I am using AXIOS:
Maybe that code is completely wrong, it is anyway like the 7th time I write it… I tried with promises, async/await, sync, and now recursion…

Answer:

You can run the axios calls in sequence (one after the other) like this:
Or, you can run them in parallel and collect the results in order:
If you run them in parallel (which may finish sooner), you have to make sure that the target server will accept however many simultaneous requests as your array is long. Some servers will limit or reject too many simultaneous requests. To run semi-in-parallel where you have N requests in flight at the same time (how you would process a large array in parallel without too many requests in flight at once), you would use something like mapConcurrent() to control the execution.

If you have better answer, please add a comment about this, thank you!

javascript node.js
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How do I use SetWindowText with Unicode in Win32 using PowerShell?

01/04/2023

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.