4 Replies Latest reply on Sep 21, 2009 8:52 AM by Calculoso

    Is there a way to process multiple asynchronous calls individually (instead of all at once)?

    Calculoso

      Hello,

       

      I have a function that saves a record using a RPC call (asyncToken with a new responder).  When I save an individual record (pressing "s" key), it works fine.  However, when I attempt to save multiple records simultaneously (bound to "v" key) (I have a for loop running through the selectedItems in the datagrid), it performs strangely.

       

      For anyone who hasn't experienced this, the successive calls seem to get stacked (literally - i.e. using a stack) and processed at the end of all operations in that block of code (I had trace functions before and after the call that were executed before I saw the result confirming this).

       

      What I would like to do is to simulate multiple AsyncToken usages with a single click, but still have them all occur individually since right now, the function saves the last item in the stack 8 times instead of saving each of the 8 items separately.

       

      OR

       

      Is there another means of RPC using something like "interruptToken" as opposed to asyncToken?  (In most other areas I've seen, asynchronous calls are performed as interrupts and dealt with immediately, thats why this procedure confused me for a bit)

       

      Thanks in advance,

        • 1. Re: Is there a way to process multiple asynchronous calls individually (instead of all at once)?
          Ansury Level 3

          I have to question the need for making multiple calls at all, when you're saving a list of items.  If you're using data services the way to do this typically is to send everything you're saving in a list (arraycollection etc), and processing that list on the server all at once.  You're adding some overhead by making multiple calls and I'm not sure I see the added benefit performance wise.

           

          If I understand what you are saying about the trace functions you had, the reason all of them would seem to execute and "finish" before the result is reached is because Flex is firing off all those requests at once and then it moves on to other tasks.  The result (or fault) handlers only get executed after a reply has been recieved from the server for each request, which takes some amount of time.  If Flex/Flash waited for those replies before moving on, everything would freeze up (even the browser's UI) because it's all single threaded, so they use an event based design.

           

          Does that help at all?

          1 person found this helpful
          • 2. Re: Is there a way to process multiple asynchronous calls individually (instead of all at once)?
            Calculoso Level 1

            The second paragraph you posted is definitely worthwhile - still figuring out some of the inner workings of Flex calls (not just RPC stuff) that I use as I am pretty new to flex.

             

            I don't have the code with me at the moment, but I think I have to use separate calls to the save function.  My situation is this (and I plan on updating with code on Monday if necessary):

             

            I have a datagrid that is populated using a single RPC (which is loaded into an arrayCollection first then the datagrid).  Changes are made to the datagrid through a copy/paste function that I made, but these changes are only reflected on the datagrid (i.e. not in the dataprovider).  When the user hits "save", the selected line (selectedItem actually - i.e. not an index but the object itself) is passed to another class which contains a modified version of my "modify data" function (brings up a dialog after choosing a given line allowing editting/validation of certain fields regarding the selectedItem).  This changed version of "modify data" is then called and immediately closed effectively saving this record (without allowing the user to alter fields - so they don't have to hit save twice).

             

            With the copy/paste function, I make all of these changes en masse and then have a loop that goes something like

             

            for each (_object:Object in myDatagrid.selectedItems)

            {

                 callSaveFunction(this, _object);

            }

             

            which ideally loops through the data and saves each item that has been changed.  If there is a way to save all of the data in the datagrid simultaneously, I would appreciate a bit of help there (perhaps dealing with the bindings - right now I have the object I save as the destination and the source is myDatagrid.selectedIndex.[field name]).

             

            Good to know about the other stuff, though - my understanding was a little bit lacking before

            • 3. Re: Is there a way to process multiple asynchronous calls individually (instead of all at once)?
              Calculoso Level 1

              FYI - I am using weborb for Flex (www.themidnightcoders.com) and the save function in the ActiveRecords api is just for a specific active record (i.e. a row in the datagrid).  I was essentially trying to develop a saveAll method that simply invokes this multiple times (though there may be a saveAll function in a different area that I am unaware of).

              • 4. Re: Is there a way to process multiple asynchronous calls individually (instead of all at once)?
                Calculoso Level 1

                I've just finished based on your suggestion about using the array collection!  I am still traversing it and calling the save function for an effective "save all" but desired to save only the dirty rows.  This did add some unnecessary complications so I appreciate the solution (while I hang my head in shame for having not done this myself -_-)

                 

                Thanks