How would I convert the following:
while True:
# do something
time.sleep(2)
into JavaScript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You would not, as JavaScript does not sleep – it is synchronous and event-based. Yet, you can schedule functions to be executed later in time via
setTimeoutandsetInterval:For your ajax progress bar, I’d recommend the following which does not fire requests strictly each 2s, but waits for them to return: