MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Multiple requests to one notification

    Scheduled Pinned Locked Moved Development
    6 Posts 2 Posters 1.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      retroflex Project Sponsor Module Developer
      last edited by

      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.js

      Now 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?

      S 1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil @retroflex
        last edited by

        @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)

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          retroflex Project Sponsor Module Developer @sdetweil
          last edited by

          @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 :)

          S 1 Reply Last reply Reply Quote 0
          • S Away
            sdetweil @retroflex
            last edited by

            @retroflex YOU might not be using promises, but request() is!..there is also promise.cascade()… a, then b, then c …

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              retroflex Project Sponsor Module Developer @sdetweil
              last edited by

              @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?

              S 1 Reply Last reply Reply Quote 0
              • S Away
                sdetweil @retroflex
                last edited by

                @retroflex i have not tried retry

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy