Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:39:42+00:00 2026-06-01T09:39:42+00:00

I have been using JavaScript as a tool for many years now, but only

  • 0

I have been using JavaScript as a tool for many years now, but only recently have I begun programming applications with it. After watching Crockford on JavaScript – Level 6: Loopage I have begun to appreciate the Event Loop and the style of not blocking. To better get to grips with this I have gone back to an app where I am believe I have a badly designed area of code.

The application downloads an ~45KB JSON file (minified, uncompressed) containing ~20 elements, so on average each element has about 2.25KB of data. The download takes place every minute, as well as being manually triggered, at which point the new array replaces the old array. Every 15 seconds the DOM is cleared out and the array is iterated over. Calculations and logic are performed on the data to create groups of DOM elements to be inserted into the DOM.

Rather than doing:

for (int i = 0; i < array.length; i++) {
  // Perform logic
}

How would I implement it in a none blocking fashion? So far I have come up with:

var performLogic = function performLogic(element) {
  // Perform logic
}

var counter = 0;
var iterator = function iterator() {
  counter += 1
  if (counter < array.length) {
    performLogic(array[counter]);
    setTimeout(iterator, 0);
  }
}

setTimeout(function() {
  counter = 0;
  iterator();
}, 0);

I can’t get my head around it. I know this will fail if the data was downloaded in between the performLogic() calls, as the array length may alter, regardless the group of data won’t be from the same array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:39:43+00:00Added an answer on June 1, 2026 at 9:39 am
    var arrayData=[], // current data array for performing logic
        newArrayData=[], // new downloaded data array for performing logic
        arrayDataIndex=0;
    
    var doAjaxRequest=function(fCallback){
      // here must be placed code which doing request for downloading data. "~45KB JSON file"
      // if success calling fCallback function and passing data.
    };
    
    var genNewDataArray=function(data){
      // here must be placed code which converts and saves "data" variable value 
      // into "newArrayData" variable value. For example:
      //   newArrayData = convertDataIntoArrayData(data);
      // next calling:
      setTimeout(newDataArrayLoaded,0);
      // or can be simply calling newDataArrayLoaded(); without setTimeout
    };
    
    var newDataArrayLoaded=function(){
      if(arrayDataIndex===0){
        arrayData=newArrayData;
        performLogicForAll();
      }
      else setTimeout(newDataArrayLoaded,0);
    };
    
    var performLogicForAll=function(){
      performLogicForOne(arrayData[arrayDataIndex]);
      arrayDataIndex++;
      if(arrayDataIndex===arrayData.length)arrayDataIndex=0;
      else setTimeout(performLogicForAll,0);
    };
    
    var performLogicForOne=function(){
    };
    
    // loading every 15 seconds a new data with help of setInterval.
    // this is not optimized! use another logic in your page.
    setInterval(function(){doAjaxRequest(genNewDataArray);},15000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using the CodeIgniter system for a while now - but it
I have been using WPF for a few years now and don't have any
I have been using the following regular expression in ASP.NET and Javascript: [a-zA-ZöäüÖÄÜß0-9]{1}[a-zA-ZöäüÖÄÜß0-9_.\-]{2,14}[a-zA-ZöäüÖÄÜß0-9.!]{1} Now,
I have been using Google Chrome's dev tool kit (element inspection, stack trace, javascript
I have been using JavaScript for couple of years and never cared about the
I have been using jQuery lately, but never used JSON with it. Now, I
I have been working on a perspective projection rendering demo using javascript, recently I
Ok, I haven't been using JavaScript without JQuery for quite some time now... But,
I have been using .replace(www., ); in javascript, but today I was thinking that
We have been using javascript hashes a lot lately, and we've been looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.