Loading ...
Sorry, an error occurred while loading the content.

Connection Manager - Multiple Posts - Catching Open Connections

Expand Messages
  • David Prusak
    Hi all, I have a very strange situation in which I need to send multiple posts to different URL s at the same time (or I could do this in a linear fashion, but
    Message 1 of 3 , Mar 1 1:10 PM
    • 0 Attachment
      Hi all,

      I have a very strange situation in which I need to send multiple
      posts to different URL's at the same time (or I could do this in a
      linear fashion, but though async would save some time for better
      user experience.

      Here's the situation. The number of posts I need to complete are
      dynamic based on the number of items the user has. Each item can
      have 0, 1 or 2 posts. Let's think of it has saving and deleting
      files and number of hard drives.

      This particular user has 2 hard drives and a list of files on each.
      They choose which to delete and which to save.

      There is 1 URL to post to for the save routine, and another URL for
      the delete routine, (which I don't have control over).

      The sudo code I have now is:

      for (each hard drive){
      if there is a saved list
      var mySave = YAHOO.util.Connect.asyncRequest
      ('POST',uiServer+'/save.php, callbackSave, savedListPostData);
      if there is a delete list
      var myDelete = YAHOO.util.Connect.asyncRequest
      ('POST',uiServer+'/delete.php, callbackdelete, deleteListPostData);
      }

      This can create multiple connection handle and what I'm, not fond of
      is the possibility of the variable getting stomp over if there are
      more than 1 hard drive.

      My question is that I know I can check to see if the connection
      handle is currently active, but can I piggy back off that same
      connection handle (multiple post objects?) so I don't create a new
      connection handle stomping on the first? Is there a way in the
      connection manager to do this?

      The reason is that after all the connections are done, I need to
      inform the user that the save/delete has successfully completed or
      errored out. With a possibility of many open connections, it
      difficult to manage this. I know I can do this in a more linear
      fashion, but I was wondering if there is a better approach.

      I hope I was able to explain this clearly :)

      Thanks!
      --David
    • Thomas S. Sha
      ... If I understand your request correctly, you can do this: var mySave = []; var myDelete = []; for (var i=0; i
      Message 2 of 3 , Mar 1 9:51 PM
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "David Prusak" <dprusak@...> wrote:

        > The sudo code I have now is:
        >
        > for (each hard drive){
        > if there is a saved list
        > var mySave = YAHOO.util.Connect.asyncRequest
        > ('POST',uiServer+'/save.php, callbackSave, savedListPostData);
        > if there is a delete list
        > var myDelete = YAHOO.util.Connect.asyncRequest
        > ('POST',uiServer+'/delete.php, callbackdelete, deleteListPostData);
        > }
        >
        > This can create multiple connection handle and what I'm, not fond of
        > is the possibility of the variable getting stomp over if there are
        > more than 1 hard drive.

        If I understand your request correctly, you can do this:
        var mySave = [];
        var myDelete = [];
        for (var i=0; i<=numberOfDrives; i++){
        if(savedList){
        mySave[i] = YAHOO.util.Connect.asyncRequest(savedListArgs);
        }
        else if(deleteList){
        myDelete[i] = YAHOO.util.Connect.asyncRequest(deleteListArgs);
        }
        }

        If there are multiple connection requests, whether a mix of mySave
        and, or myDelete, you will have a unique reference to the request, in
        the event you should ever have to abort it or check its progress.
        Moreover, the createXhrObject method is essentially an object factory
        that returns a new XHR for each request.

        Hope this helps.

        Regards,
        Thomas
      • David Prusak
        ... deleteListPostData); ... fond of ... are ... in ... factory ... Hi Thomas, That s what I progressed to. I have an array of objects now. Each connection
        Message 3 of 3 , Mar 2 12:46 AM
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, "Thomas S. Sha" <tsha@...>
          wrote:
          >
          > --- In ydn-javascript@yahoogroups.com, "David Prusak" <dprusak@>
          wrote:
          >
          > > The sudo code I have now is:
          > >
          > > for (each hard drive){
          > > if there is a saved list
          > > var mySave = YAHOO.util.Connect.asyncRequest
          > > ('POST',uiServer+'/save.php, callbackSave, savedListPostData);
          > > if there is a delete list
          > > var myDelete = YAHOO.util.Connect.asyncRequest
          > > ('POST',uiServer+'/delete.php, callbackdelete,
          deleteListPostData);
          > > }
          > >
          > > This can create multiple connection handle and what I'm, not
          fond of
          > > is the possibility of the variable getting stomp over if there
          are
          > > more than 1 hard drive.
          >
          > If I understand your request correctly, you can do this:
          > var mySave = [];
          > var myDelete = [];
          > for (var i=0; i<=numberOfDrives; i++){
          > if(savedList){
          > mySave[i] = YAHOO.util.Connect.asyncRequest(savedListArgs);
          > }
          > else if(deleteList){
          > myDelete[i] = YAHOO.util.Connect.asyncRequest(deleteListArgs);
          > }
          > }
          >
          > If there are multiple connection requests, whether a mix of mySave
          > and, or myDelete, you will have a unique reference to the request,
          in
          > the event you should ever have to abort it or check its progress.
          > Moreover, the createXhrObject method is essentially an object
          factory
          > that returns a new XHR for each request.
          >
          > Hope this helps.
          >
          > Regards,
          > Thomas
          >

          Hi Thomas,

          That's what I progressed to. I have an array of objects now. Each
          connection has something like:

          mySaveArray[0]
          .connection
          .postData
          .otherData

          etc..

          The problem I'm having now, is that I have multiple connections
          created and they all call the success/fail callback function. The
          trouble I'm having is catching or logically knowing that all
          connections have finished one way or the other.

          What I've done to get around that is to count the number of elements
          in the array (length) and with a global variable, count the number
          of times the success or failure callback is called. It works, but
          it's really messy.

          What I was asking for is that if one would have to make multiple
          async connections, if it could be bundled one 1 connection (possibly
          creating an object of connections and passing it to the connection
          manager). When all have completed, return the object with a
          success/fail for each. It would be cleaner to process a single
          return than multiple returns. (of course, I'm missing a strong point
          here :) )

          Thanks!
          --David
        Your message has been successfully submitted and would be delivered to recipients shortly.