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

  • Home
  • SEARCH
  • 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 8018055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:01:36+00:00 2026-06-04T21:01:36+00:00

After using node a lot, I had to get used to writing my code

  • 0

After using node a lot, I had to get used to writing my code in a non-blocking way, however the main way I can do this is by using functions that are themselves asynchronous. For example: stat(f,callback) or forEach(array, callback) They automatically take whatever callback you gave them out of what I would think to be the main execution highway and return immediately after being called.

What I want to know is: how can I tell the ECMA engine to execute a function asynchronously nomatter what it is?

My Particular use case involves iterating a for-loop over a DOM childList to parse the thousands of elements; my problem is that every other element is a text node which I’d like to skip over. While I would use forEach() this was not best, I only see for(a,i=0;a=table[i];i=i+2){/*process 'a'*/} being able to rectify that, at the cost of being blocking. What would be the best course of action?

Bonus Question: Does NodeJS’s coding practices hold any ground in clientside applications in use cases where JS has to do heavy lifting?

  • 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-04T21:01:39+00:00Added an answer on June 4, 2026 at 9:01 pm

    Note: Array.prototype.forEach is synchronous, not asynchronous. Anything defined in the JS standard (ECMAScript 5th edition) cannot be asynchronous, because the standard does not define async semantics (Node.js and the DOM do).

    You can use setTimeout (works in browsers and in Node.js) or process.nextTick (Node.js-specific):

    for (...) {
        doWorkAsync(...);
    }
    
    function doWorkAsync(...) {
        setTimeout(doWorkSync.bind(null, ...), 0);
    }
    
    function doWorkSync(...) {
        ...
    }
    

    Be careful when using free variables if you choose to exploit closures, as the variables may be mutated when your callback is finally called.

    With an async framework, such as Q by kriskowal (portable across Node.js and modern browsers), you can do mapreduce-style programming:

    var Q = require('q');  // npm package 'q'
    
    function getWorkloads() {
        var workloads = [ ];
        for (...) {
            workloads.push(Q.fcall(doWorkSync.bind(null, ...)));
        }
        return workloads;
    }
    
    Q.all(getWorkloads()).then(function (results) {
        // results array corresponds to
        // the array returned by getWorkloads.
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After using this code to get my link to show me 3 database entrys
I'm using the following library https://github.com/Leonidas-from-XIV/node-xml2js To convert XML to JSON. After conversion console.log
After using Instruments, I have found the a spot in my code that is
If I get the path to a specific node as a string can I
I'm writing an integration test for a rails application using Capybara within Rspec. After
I've been writing some code that extracts the main textual content from web pages.
I am using Node.js and Mongoose to store some data. After update, I have
Here is how I've done: https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger but in the image after Now start making
In Drupal , Am using node_delete function for delete the node, After deleted by
Using Express (for node.js ) How do I write a response after a callback?

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.