Linked Questions
16 questions linked to/from What's the equivalent of Java's Thread.sleep() in JavaScript?
2641
votes
81answers
3.1m views
What is the JavaScript version of sleep()?
Is there a better way to engineer a sleep in JavaScript than the following pausecomp function (taken from here)?
function pausecomp(millis)
{
var date = new Date();
var curDate = null;
do ...
289
votes
15answers
154k views
Why doesn't JavaScript support multithreading?
Is it a deliberate design decision or a problem with our current day browsers which will be rectified in the coming versions?
142
votes
13answers
139k views
9
votes
7answers
26k views
Add a delay after executing each iteration with forEach loop
Is there an easy way to slow down the iteration in a forEach (with plain javascript)? For example:
var items = document.querySelector('.item');
items.forEach(function(el) {
// do stuff with el and ...
12
votes
2answers
10k views
setTimeout - how to avoid using string for callback?
When using setTimeout, you have to put the code you want to execute into a string:
setTimeout('alert("foobar!");', 1000);
However, I want to execute a function to which I have a reference in a ...
8
votes
7answers
28k views
delay/sleep in javascript?
Is there a simple way to pause the script in Javascript? I'm looking for the javascript equivalent of time.sleep(1) in Python. I do NOT want setTimeout(continueExecution, 10), or anything with getTime....
3
votes
8answers
71k views
How to do a script for odd and even numbers from 1 to 1000 in Javascript?
I am studying a book of Javascript with solved examples but there is one example without solution. I would like to know how to do it ...
In javascript (in browser) I should do is write even numbers ...
0
votes
6answers
472 views
Add delay between 'for' loop iterations
I'm trying to implement basic 60 sec counter(A p element with idcounter), that is triggered after a button(counter_start()) is pressed.But I want delay of 1 sec between this and make sure this updates ...
1
vote
1answer
627 views
sleep equivalent in Javascript [duplicate]
I'm working on a simple web animation. Thing is, I was used to work on C code, and delay my functions using sleep() and usleep(). ATM, I'm trying to write a function that slowly draws a rectangle by ...
1
vote
1answer
379 views
How to use a thread timer? ASP.NET
how are you?
I need to use two commands in my application, however, need to be performed with a time interval between them.
I tried using thread to solve my problem, but could not.
This is the code:...
0
votes
2answers
109 views
How to get two events to occur with delay between them
So, I have a few a strings loaded into an array called messages. I want to cycle through the messages with a half second period where no message is showing. My code should do that, but for whatever ...
0
votes
2answers
152 views
Stop main/current thread and let callbacks finish
In essence I have a piece of code somewhat like:
function closeServerGracefully() {
setTimeout(process.exit, 1000);
}
if (failingCondition) {
logger.log('error', 'Fatal error exiting because ...
0
votes
1answer
62 views
Loop blocks DOM manipulating code before it
Here I use the loop code(learned from What's the equivalent of Java's Thread.sleep() in JavaScript?) to simulate web latency to check my loading animation effect. However, the first line is ...
1
vote
1answer
47 views
Making a function that adds delayed callback to any function?
I want to have a function that can add callback to any function with a delayed timing.
Lets say I have a function :
function name(val) {
document.write(val);
};
Now, adding delayed callback to ...
-2
votes
1answer
41 views
I need a delay when I change some text
I need a hint! I want to change some text with a delay in it. With .delay it isn't working because it isn't a queue. Then I tried it with .setTimeout. That worked, but only for one textbox. When I add ...