Read the statement by Michael Teeuw here.
Multiple requests to one notification
-
This is more of a javascript question I guess…
Let’s take an example where request gets a result, parses it and sends it to the client:
https://github.com/mykle1/MMM-Cocktails/blob/master/node_helper.jsNow how would I go about if I in that getCocktails function wanted to request 2 URL’s, parse them to one combined result and send that as payload with one socket notification?
Or maybe I should do it in a completely different way?
-
@retroflex see https://stackoverflow.com/questions/19911429/nodejs-multiple-http-requests-in-loop
to use an array to hold the concurrent promises and then wait for all to complete (vs any() which triggers if any complete)
-
@sdetweil Great, thanks a lot! Now I remember I read up on promises a long time ago, but never got around to use it. I’ll try it out when I have the time.
Maybe I’ll learn javascript for real some day, it’s just every time I program anything I just get annoyed by the loose typing :)
-
@retroflex YOU might not be using promises, but request() is!..there is also promise.cascade()… a, then b, then c …
-
@sdetweil thanks again for the tip about promises. I managed to get it working with request-promise and Promise.All in my new MMM-Fortnite module. So now my son is happy 😀
Since the API I’m using is a bit unstable I also tried request-promise-retry package, but never got any usable return value from that. Do you have any experience with retries?
-
@retroflex i have not tried retry