HISE Logo Forum
    • Categories
    • Register
    • Login

    return values from async calls

    Scheduled Pinned Locked Moved Feature Requests
    7 Posts 3 Posters 645 Views
    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.
    • LindonL
      Lindon
      last edited by

      It would be really nice (and something you could check) if the async calls had return values for success or failure (1 or 0), for example:

      var myResult = Engine.loadUserPreset("bah/blah/blah");

      It would be even nicer if you could define a function that got called on return but hey...small steps...

      HISE Development for hire.
      www.channelrobot.com

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        What you can already do is to attach a function that is executed when the preload state changes so you can implement custom sample preloading bars. If you just want to react on user preset changes, take a look at the solution posted in the other thread.

        But its a good idea and every method that returns void can be changed to return a error code. However its a bit unclear what a "success" in this case is:

        • Does the file exist?
        • Is it a valid XML file?
        • Does the version match or does it contain any controls that aren't part of the current instrument or have the wrong type?

        The more you go down this list, the more stuff it has to do synchronously and at some point it looses the advantages of an async call (which is instant returning).

        LindonL 1 Reply Last reply Reply Quote 0
        • LindonL
          Lindon @Christoph Hart
          last edited by Lindon

          @Christoph-Hart

          Well async in my world isnt "instant returning" cause if they were they could be syncronous, there's obviously some indeterminate wait period, which is fine I get that.

          We can define success (and their return codes as) in this way:

          A file exists and got loaded = 1 (after that you are on your own)

          Failure is:
          file not exist or fail to load = 0

          If I dont define and create a correct piece of XML or if its got some extra params or some missing = my problem not yours.

          You are right you could end up down a rabbit hole - so just dont go there:

          The nice outcome is:

          var myReturn = -1;
          myReturn = Engine.loadUserPreset(......);
          
          While (myReturn = -1){
              wait(1000);
          };
          

          (Yes I know there is no simple wait statement - and yes I think there should be...but thats another request for another day)

          HISE Development for hire.
          www.channelrobot.com

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @Lindon
            last edited by

            @Lindon You can achieve a while wait loop using a timer callback.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            LindonL 1 Reply Last reply Reply Quote 0
            • LindonL
              Lindon @d.healey
              last edited by

              @d-healey yes I know I can.... but that doesnt meet the criteria of "simple" I think...

              HISE Development for hire.
              www.channelrobot.com

              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @Lindon
                last edited by

                @Lindon

                @d-healey yes I know I can.... but that doesnt meet the criteria of "simple" I think...

                JavaScript, on which HISE script is based, doesn't have a wait/sleep type thing and I don't think it's a good idea to start tacking on bits of KSP to solve a problem that doesn't really exist. I agree that writing less lines of code = simpler but I'm not sure the difference in level of simplicity is as important as the functionality which is already there.

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  Yes, implementing a sleep functionality in a multithreaded environment is the worst. I have played around with this, but it involves stack unrolling and restoring the value of every local variable.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  47

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  101.9k

                  Posts