I'm a bit sorry about tags, probably I understood my problem not right and used them wrong but..
The problem I'm faced with my project is new for me and I never before experienced it. So in my case I have a huge dataset response from DB (Mongo, 100'000+ docs) and I needed to http-request
every specific field from doc.
Example array from dataset will be like:
{
_id: 1,
http: http.request.me
},
{
//each doc of 99k docs more
}
So guess you already understood that I cannot use default for loop
because
- if it
async
I'll be made a huge amount request to API and will be banned/restricted/whatever - if I made it
one-by-one
it will take me about 12-23H of waiting before my loop completes itself. (actually, this way is in use)
This is what I'm trying to do right now
there is also another way and that's why I'm here. I could split my huge array in to chunks for example each 5/10/100..N and request them
one-by-one
│→await[request_map 0,1,2,3,4]→filled │→await[request_map 5..10]→filled │→await[request_map n..n+5]→filled ↓
According to the Split array into chunks I could easily do it. But then I should use 2 for
cycles, first one will split default array and second async-request
this new array (length 5/10/100...N)
But I have recently heard about reactive paradigm and RxJS
that (probably) could solve this. Is this right? What operator should I use? What keyword should I use to find relative problems? (if I google reactive programming I'll receive a lot of useless result with react.js but not what I want)
So should I care about all this and just write an unoptimized code or there is an npm-module
for that or another-better-pattern/solution?
Probably I found and answer here RxJS 1 array item into sequence of single items - operator I'm checking it now, but I also appreciate any relevant contribution to this question
RxJS has truly been helpful in this case and worth looking. It's an elegant solution for this kind of problems