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 8643185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:58:13+00:00 2026-06-12T11:58:13+00:00

my task is to do a long running JS code. This routine generate a

  • 0

my task is to do a long running JS code. This routine generate a POST request, and when its over and need to, generates another according to the answer:

function routine (a)
{
    var answer = createPostRequest (bla bla bla);
    if (answer)
    {
        routine (a);
    }
}

so it recursively calls itself as long as the answer is true. So far its good, but then browser freezes, or hangs too much. After a time, Firefox will tell me that script is running too long, and offers to stop it.
Instead of doing routine (a); I tried to do with a setTimeout with timing 1. The same things, but when I set 100 for timing, it looks ok. But there are unnecessarry waitings, plus its a subjective number (what if even that 100 causes problems?)
I need some kind of “message based” thing, like in Delphi/Windows programming: a program sends a message to itself. How can it be achived in JS?

Edit: the way I generating the request:

var ajax = createXmlHttp();
ajax.open ('POST', 'dsdsdsad.adsf', false);
var parameters = 'param=1';
ajax.setRequestHeader ('Content-type', 'application/x-www-form-urlencoded');
ajax.setRequestHeader ("Content-length", parameters.length);
ajax.setRequestHeader ("Connection", "close");
ajax.send (parameters);
try
{
    var answer = eval('(' + ajax.responseText + ')');
}
catch (error)
{
    alert ('Error in the answer: '+ajax.responseText);
    return;
}
  • 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-12T11:58:14+00:00Added an answer on June 12, 2026 at 11:58 am

    I would assume your createPostRequest makes an AJAX call that can handle a callback.

    If so, make sure the request is asynchronous and pass it a callback that tests the condition and makes the next call if needed.

    function createPostRequest(address, callback) {
        var ajax = createXmlHttp();
        ajax.open ('POST', address, true); // make it async
    
        var parameters = 'param=1';
        ajax.setRequestHeader ('Content-type', 'application/x-www-form-urlencoded');
        ajax.setRequestHeader ("Content-length", parameters.length);
        ajax.setRequestHeader ("Connection", "close");
    
            // handle the async response
        ajax.onreadystatechange = function() {
                                    if (ajax.readystate == 4) {
                                       try {
                                           callback(eval('(' + ajax.responseText + ')'));
                                       } catch {
                                           callback(null);
                                       }
                                    }
                                  };
        ajax.send (parameters);
    }
    

    function routine (a) {
        createPostRequest (bla bla bla, function(answer) {
            if (answer) {
                routine (a);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that inside a Windows Form, I start a long-running task like this:
I'd like to start a long running task on the Backend instance. This backend
I have a need to start a new thread for a long running task
I need to invoke a long running task via a SOAP web service, using
I am working on php script that may involve a long running task. The
I have an Activity with a button that starts a long running task. I
I am interested in running a very long running rake task, one that would
I'm working with the Twitter Gem and I've created a long running ruby task.
I have a Windows service which performs a fairly long running task. At the
I have a long running task that I want completed, even if the application

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.