Getting Intermediate Results Reported Right Away


G

Gene Wirchenko

Dear JavaScripters:

I sometimes want to run something for quite some time. An
example is when I am checking system limits, but later, it could be
something such as processing transactions.

I could let it run blind, but especially when testing, that is
not a good idea. I could put alert()s in, but then I get interrupted
by them. I would like to be able to start whatever it is going and
watch (or not).

How can I simply have JavaScript report as it is executing? Like:
100 things done
200 things done
300 things done
...

Sincerely,

Gene Wirchenko
 
Ad

Advertisements

A

Andreas Bergmaier

Gene said:
I sometimes want to run something for quite some time. An
example is when I am checking system limits, but later, it could be
something such as processing transactions.

I could let it run blind, but especially when testing, that is
not a good idea. I could put alert()s in, but then I get interrupted
by them. I would like to be able to start whatever it is going and
watch (or not).

How can I simply have JavaScript report as it is executing? Like:
100 things done
200 things done
300 things done
...

Have you ever tried console.log / console.debug? The debugger of your
choice will be able to show these logs. But don't flood them, that might
slow down your system!
Another possiblity is to show a fixed-positioned element on your page (I
guess you want test in Browser environment) to which you can append your
logging messages.

Bergi
 
T

Tim Streater

Gene Wirchenko said:
Dear JavaScripters:

I sometimes want to run something for quite some time. An
example is when I am checking system limits, but later, it could be
something such as processing transactions.

I could let it run blind, but especially when testing, that is
not a good idea. I could put alert()s in, but then I get interrupted
by them. I would like to be able to start whatever it is going and
watch (or not).

How can I simply have JavaScript report as it is executing? Like:
100 things done
200 things done
300 things done
...

In Safari, instead of using:

alert (str);

you can use:

console.info (str);

which puts in the the error console area (Develop -> Show error
console). If you have that open you can watch the progress.
 
H

Hans-Georg Michna

I sometimes want to run something for quite some time. An
example is when I am checking system limits, but later, it could be
something such as processing transactions.

I could let it run blind, but especially when testing, that is
not a good idea. I could put alert()s in, but then I get interrupted
by them. I would like to be able to start whatever it is going and
watch (or not).

How can I simply have JavaScript report as it is executing? Like:
100 things done
200 things done
300 things done
...

Gene,

check http://winhlp.com/node/633 for some hints.

You have to temporarily halt JavaScript processing to allow the
browser to render your results to the DOM and then to the
screen. The article shows ways of how to do that.

Hans-Georg
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
I sometimes want to run something for quite some time. An
example is when I am checking system limits, but later, it could be
something such as processing transactions.

I could let it run blind, but especially when testing, that is
not a good idea. I could put alert()s in, but then I get interrupted
by them. I would like to be able to start whatever it is going and
watch (or not).

How can I simply have JavaScript report as it is executing? Like:
100 things done
200 things done
300 things done

Choose a browser in which window.status displays, or can be set to, an
updating status line or part-line while code is running. IE8, Opera
11.52, Safari 5.1.1, for example.

Test : for (J=0 ; J<1e6; J++) if (!(J%1e5)) window.status = J


Choose a browser in which the screen, or a certain element, updates, or
can be set to, a line while code is running. Testing is easy enough.


You may cover more browsers by setting both of the above. TIEE.

Run your code 100 things at a time, with the end of a block writing the
status to something and starting the next block after a short timeout
which will allow redraw. You have already been told how to do that.
 
G

Gene Wirchenko

check http://winhlp.com/node/633 for some hints.

You have to temporarily halt JavaScript processing to allow the
browser to render your results to the DOM and then to the
screen. The article shows ways of how to do that.

The way that I have found is to set a timeout and stop execution,
then continue execution after the timeout has expired. It does make
for odd-looking code.

Sincerely,

Gene Wirchenko
 
Ad

Advertisements

D

Denis McMahon

The way that I have found is to set a timeout and stop execution,
then continue execution after the timeout has expired. It does make for
odd-looking code.

It depends on why you want periodic output.

When I'm trying stuff out in a browser environment, I might use alert
boxes for occasional outputs, or form elements for more non-interactive
output.

Appending lines of output to a textarea can be useful eg:

function printScreen(str) {
document.getElementById("id_of_textarea").value += str + "\n";
}

Rgds

Denis McMahon
 
Ad

Advertisements

T

Thomas 'PointedEars' Lahn

Denis said:
When I'm trying stuff out in a browser environment, I might use alert
boxes for occasional outputs, or form elements for more non-interactive
output.

Appending lines of output to a textarea can be useful eg:

function printScreen(str) {
document.getElementById("id_of_textarea").value += str + "\n";
}

You would. *Any* fairly modern browser (even IE) has or can be augmented
with an error console that you can print to in various ways, so *none* of
those kluges are necessary anymore.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top