Alternative to busy-wait

K

Kirsten

Have you found any solution to a pause/sleep sentence in Javascript? Or what
about mutex, critical sections, etc?

I googled and I found a solution for IE using showModalDialog (very
interesting), but I need something compatible with Firefox:

function pause(numberMillis) {
var dialogScript =
'window.setTimeout(' +
' function () { window.close(); }, ' + numberMillis + ');';
var result =

window.showModalDialog(
'javascript:document.writeln(' +
'"<script>' + dialogScript + '<' + '/script>")');

}
 
K

Kirsten

I know this function but it isn't what I need. How do you do the following
with timeouts?

sentence1;
sleep(1000);
sentence2;
sentence3;

---->
sentence1;
window.settimeout("sentence2; sentence3;", 1000)

This would complicate too much my code.
There is no such thing as a mutex in scripting as you can't create
threads. Likewise is there no "critical sections".
Maybe, but there is concurrency -- in my particular case between iframes.

Thanks.
 
J

Jens Peter Karlsen [FP MVP]

See inline.
I know this function but it isn't what I need. How do you do the following
with timeouts?

sentence1;
sleep(1000);
sentence2;
sentence3;

---->
sentence1;
window.settimeout("sentence2; sentence3;", 1000)

This would complicate too much my code.

This is the only way to do it in Scripting. It is just too bad that it
complicates your code.
Maybe, but there is concurrency -- in my particular case between iframes.

There are no concurrency either. You may call a function in another
frame but they will run independently.

If you described your problem someone might be able to come up with a
solution.

Regards Jens Peter Karlsen. Microsoft MVP - Frontpage.
 

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