Home Search Member List Faq Register Login  
JavaScript Tips
Handle asynchronous operations with minimally growing arrays

Thread Starter: Karamasoft   Started: 09-18-2007 12:46 PM   Replies: 0
 Karamasoft Support Forums » General Discussions » JavaScript Tips » Handle asynchronous operations with minimally growing arrays
 Printable Version    « Previous Thread   Next Thread »
  18 Sep 2007, 12:46 PM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Handle asynchronous operations with minimally growing arrays

When you work with asynchronous AJAX callbacks, you might need to store the callback results in an array to process them later. The tricky part is to keep the array size at minimum. In order to do this, you can empty the array item when you are done with processing it and make it available for future callback results and always insert the new callback result to the first available array item.

function InsertActiveCallbackArr(arrayObj, arrayElem) {

var i = 0;

for (var loopCnt = arrayObj.length; (i < loopCnt) && arrayObjIdea; i++);

arrayObjIdea = arrayElem;

}

When you are done with the callback result, simply set that array item to null.

function ProcessActiveCallbackArr(arrayObj) {

for (var i = 0, loopCnt = arrayObj.length; i < loopCnt; i++) {

// Process the callback result here

// Then set the array item to null

arrayObjIdea = null;

}

}


  
 Page 1 of 1 (1 items)
Karamasoft Support Forums » General Discussions » JavaScript Tips » Handle asynchronous operations with minimally growing arrays

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.