Questions tagged [settimeout]

setTimeout is a global JavaScript method, used to execute a particular function or piece of code after a given delay.

setTimeout is a JavaScript function, which executes a piece of code after a given delay.

The delayed code has to be defined via the first argument. This can be a function reference, or a plain string. Passing a string is not recommended, for the same reasons that the use of eval is discouraged.

The delay is defined in milliseconds. In all browsers except for Internet Explorer 9 and earlier, additional parameters can be added, which are passed to the function.

setTimeout returns a timeout ID, which can be passed to clearTimeout to cancel the execution of the delayed function.

To perform an action repetitively at an interval, use setInterval and clearInterval.

References

5293 questions
1
vote
1 answer

Postman Collection Run does pause for setTimeout calls

I put a simple setTimeout(function(), 10000) call in the Tests section of a request. Works fine when I run the step by itself. When I do a Collection Run, the step just gets executed and Postman moves on without pausing. Is this by design? I'd…
Guy
  • 666
  • 1
  • 10
  • 34
1
vote
2 answers

Concurrency in node js express app for get request with setTimeout

Console log Image const express = require('express'); const app = express(); const port = 4444; app.get('/', async (req, res) => { console.log('got request'); await new Promise(resolve => setTimeout(resolve, 10000)); console.log('done'); …
Phani Vvs
  • 61
  • 7
1
vote
3 answers

JS setTimeout Not Delaying

Alright guys, I'm trying to add numbers on my page every 1/4 second or so. So the change is visible to the user. I'm using setTimeout and all my calculations are occurring correctly but without any delay. Here's the code: for(var i = 0; i < 10;…
ExceptionLimeCat
  • 6,191
  • 6
  • 44
  • 77
1
vote
5 answers

React Hooks Change Text of Button on Click and then back again

Using React Hooks I would like to change the text of my button when a user clicks it to say "Added" and then I would like to set it back to the original text "Add to Cart" after 1 second. I assume I would use setTimeout for this but am having…
krichey15
  • 591
  • 6
  • 14
1
vote
1 answer

JavaScript: animate list item sequentially one at a time repeatedly

I am trying to animate a list item sequentially one at a time repeatedly. Where I have a list containing some list items. What I want to do is use javascript to animate each list item one at a time. I also have to remove the animation from the…
naveen
  • 223
  • 1
  • 2
  • 11
1
vote
0 answers

SetTimeout and return without Promises

I have simple task: I have some menu, and I need to cook it, each dish has it's own timer. When everything will be ready, I have to receive an array, that the dishes from menu are ready, but I'm getting undefined, because return will be executed…
Mr. Oleg
  • 37
  • 3
1
vote
2 answers

How can I send a new prop to a component after time using the setTimeout() function?

I have a component called flash that is intended to be in the DOM only for 5 seconds (it's a message informing the user that he has sent the post successfully) and I want it to start fading away after 2 seconds, so that after 5 seconds when it's…
ms3300
  • 216
  • 6
  • 13
1
vote
2 answers

setTimeout in $.each

I'm trying to animate characters '1-by-1', but i cant seem to figure out, why this code isn't working properly: $('.overlay-listing').hover(function(){ var idx = 1; $('.strip-hov span', this).each(function(){ if…
1
vote
2 answers

Refresh Datas after each second in js (async functions)

In the code below you can see async functions, first one to fetch some data, and the second is to build a graph with data that have just been fetched. It works perfectly but I would like to refresh the data each second. I have put setInterval…
Simon
  • 209
  • 4
  • 12
1
vote
4 answers

Cannot control the order of asynchronous tasks using promise

I am facing an issue while using promise to control async tasks in JavaScript. In the following code, I wanted to output 'first' before 'second'. I used promise then block, but it didn't work as I wanted. I used setTimeout to create different time…
Sonet Adhikary
  • 466
  • 1
  • 4
  • 8
1
vote
1 answer

How to play audio upon exiting a timer function the next part of the function?

I'm trying to add a piece of audio that plays (only once!) when the timer reaches zero. It's a Pomodoro timer, so the first timer goes down to zero, should play the audio, and then the next part of the same function 'break' should run: function…
1
vote
1 answer

For loop prints wrong branch of if-else statement first

the following code is just to test the functionality for (var i = 1; i <= 5; i++) { if(i==4){ console.log(document.getElementById("loading").classList.contains("invisible")); break; }else{ (function(i){ setTimeout(function() {…
1
vote
1 answer

Setinterval - One click then another Click after 2 seconds. Run Once. NO LOOP

I have looked at many Posts regarding setInterval and none of them have the answer I am looking for or what I am trying to achieve what I want. I am looking for one setInterval function with 2 clicks. The first click is separated by 2sec from the…
Jvaskana
  • 53
  • 9
1
vote
3 answers

setTimeout Functionality in JavaScript

I'm trying to understand the concept of setTimeout and I couldn't understand how it works. In the below example, when I gave the 1000 to the second setTimeout function I got the output as 1)Hello 567 2)Hello 3)Hello 123 But When I gave the…
Hema Nandagopal
  • 668
  • 12
  • 35
1
vote
2 answers

Han can I increase the time value in a setTimeout function when a button is clicked?

I have a function named showAlert that displays an alert. I have used the setTimeout function to delay it by 5 seconds. I have a button that should increase the delay by an additional 5 seconds. How can I do this?
1 2 3
99
100