4 Replies Latest reply on Jun 26, 2007 7:29 PM by ntsiii

    Daisy-chaining remote object calls

    doug777 Level 1
      If you want to get data from a series of CFCs using remote object, and each call depends on data received from the previous call, you have to daisy-chain the functions making the calls, otherwise there is no way to guarantee that the data is available in time (in practice it is never available in time) because the main thread races on regardless.

      Now if you want to refresh parts of the data, or you want to get a different set of data from one or more of the same CFCs, you either can use the same functions and set up a different set of daisy-chains with multiple boolean tests to see which chain of links should be being followed ( and this ends up something akin to a four-dimensional Hampton Court maze), or you have to duplicate the remote calls over and over again in different sets of functions and resultHandlers. Either way you end up with a horrible mess.

      Is there any way to write a class that can suspend the main thread, pending a remote call listener sending a resume main thread event.

      The other way that would work (though this would not be as good) is to change addEventListener, so that you can pass arguments into the resultHandler.

      Does anyone have any ideas that could lead to a solution to this problem? It's giving me gray hair.

        • 1. Re: Daisy-chaining remote object calls


          This might be quite a shift in thinking, however if you use the Cairngorm Framework, and then use the SequenceCommands from the CairngormDocs site that would only trigger your next command in the sequence.

          Cairngorm, is available on the Adobe Labs site, its quite a bit to get your head around, but is well worthwhile when you do... Check on the www.cairngormdocs.org site for help with Cairngorm..

          Good luck
          • 2. Re: Daisy-chaining remote object calls
            ntsiii Level 3
            "suspend the main thread, pending a remote call.." No. Can't be done.

            ..."pass arguments into the resultHandler..." Yes, this is done using the AsyncToken. (ACT pattern)

            The send() methods returns an AsyncToken object. You can use this dynamic object to add almost anything you want to the token, including strings, and functions (google the term "closure").

            As I am still not comfortable with anonymous functions, I like to pass strings. I pass an identifier, which I can use in a switch statement to determine the next step. Sometimes I pass a "nextStep" string to define finer grain conditionality.

            I use a single dataService object and result handler function for all calls.

            • 3. Re: Daisy-chaining remote object calls
              doug777 Level 1
              Wow I never understoood what AsyncToken did before, but you're right this is the solution.

              I also notice AsyncRequest, and I need to find a way to advise the user if a remote call fails due to his internet connection having failed for some reason. Is there a way to specifically identify 'no internet connection' when remote service called and report it using AsyncRequest?

              Thanks for your help,
              • 4. Re: Daisy-chaining remote object calls
                ntsiii Level 3
                Sorry, I haven't used that.