Skip to main content
Filter by
Sorted by
Tagged with
-3 votes
1 answer
65 views

recursion with setTimeout flow anomaly

Please see the below code. I thought the '11111111' line would never be executed but it is. Can anyone please explain. function outer() { function inner(dur) { console.log('in inner'); ...
rajplayster's user avatar
-1 votes
0 answers
42 views

jQuery $(window).on("load", function(){ //content here }); not working for the below code [closed]

I am trying to load loading text on every reload of the page means if ctr+r is pressed or F5 is pressed the loading text should show. From my current jQuery code it is not working with $(document)....
mayursthakor's user avatar
0 votes
0 answers
14 views

set timeout -1 is endless and not executing in expect

I am writing an expect script that helps me run a program. When i set the timeout to 10 or 30, the program runs although since it's a big run installation, it doesn't get completed within 30 seconds. ...
Priyansh Mehta's user avatar
0 votes
0 answers
29 views

How to cover with unit test a settimeout in a event listener in angular method?

Using jasmine and karma, I can pass the unit test using fake async and using a real event, but the coverage is not correct, the settimeout call back is ignored. @Component({ selector: 'slider', ...
Tabares's user avatar
  • 4,277
0 votes
1 answer
31 views

How can I reset Timeouts/animations? (Ionic/Angular)

I want to display some messages in a sort off in app notification. It is supposed to behave like this: click on a button notification slides down + display text notification slides back up If there ...
Mateus Oliveira's user avatar
0 votes
1 answer
50 views

Terminating Bubble Sort Algorithm when the dataset has been sorted

This function goes through the dataset and then sorts it in ascending order. What its meant to do is stop when the list has been sorted. However, the !changed control flow statement terminates it ...
That wolphin's user avatar
0 votes
1 answer
17 views

How to pause every ticking setTimeout and setInterval timer collectively - then unpause/resume/continue when needed

For modern web apps, simulating an app freeze/unfreeze can become necessary. One example is when you don't want the user to miss seeing any of the dynamic content that your page/screen/website/app has ...
TheNightwalker's user avatar
0 votes
0 answers
30 views

load event doesn't fire in iframe when code is broken up with setTimeout

We have an in house js framework that contains JS functions specific to a number of controls that can be used on a page. Some of these controls need js initialising at different points i.e. immediate (...
Chris Spittles's user avatar
0 votes
1 answer
31 views

How to ensure user logout with Web Worker when the computer goes to sleep

I’m using a Web Worker to set a setTimeout that automatically logs out the user after 10 minutes of inactivity. However, I’ve encountered an issue where if the user’s computer goes to sleep, all ...
YI LU's user avatar
  • 21
0 votes
0 answers
22 views

Unexpected behavior of setTimeout/setInterval when tab is inactive [duplicate]

I've implemented a user activity tracking and countdown timer in React using setTimeout and setInterval. Everything works fine when the browser tab is active, but I'm facing issues when the tab is ...
YI LU's user avatar
  • 21
-1 votes
1 answer
56 views

Can clearTimeout prevent the execution of a callback which has already been moved to the callback queue?

Consider a scenario where I have two tasks - Task 1 is a callback which is set to be executed after 1 sec using setTimeout. Task 2 is a synchronous/blocking task which takes comparatively more time ...
Arman Lalani's user avatar
0 votes
0 answers
24 views

why setTimeout executed first then the setImmediate in nodeJS-v20.11.0 [duplicate]

console.log("---------Event Order---------"); const fs = require('fs'); const path = require('path'); const currentDir=__dirname const fileName='example.txt' const filePath=path.join(...
Rishu Singh's user avatar
0 votes
0 answers
30 views

Settimeout for multiple elements

I have an array of entities mapped, and a different timer is started for each. But when the time expires, both are reset (the callback function is executed that the time is up), but you want the other ...
Roman Nozhenko's user avatar
0 votes
0 answers
27 views

is ng-grid.js CSP compatible?

I am using the ng-grid.js library in my AngularJS project and need to verify if setTimeout and eval() are functioning correctly after removing unsafe-eval from the Content Security Policy: <add ...
Abhishek Sharma's user avatar
1 vote
1 answer
68 views

automatically loop through radio buttons but also be able to manually switch

I'm trying to iterate through radio buttons automatically every 5 seconds via jquery; however i need the function to also run when i manually switch buttons. Here's what I have so far: $(document)....
amy's user avatar
  • 85
0 votes
0 answers
53 views

setTimeout() is not Working in Jets Unit Test

Here I have perform testing on jest. When I tested for setTimeout() function, it didn’t work. Any help would be appreciated. I have followed this documentation: https://jestjs.io/docs/timer-mocks ...
Jay Patel's user avatar
1 vote
3 answers
44 views

Stop text-rotator timeout when array ends

My code works fine, but it never ends. How can I stop the rotator after Word6? I have tried one more setTimeout but it's not working. const phrases = ['Word1', 'Word2', 'Word3', 'Word4', 'Word5', '...
Andreas Thomsson's user avatar
0 votes
2 answers
74 views

Where are anonymous callback functions to setTimeout stored?

I have a simple program that looks like this: console.log("Start of the program execution!"); setTimeout(() => { console.log("I ran after a second!"); }, 1000); console....
mukesharyal's user avatar
0 votes
1 answer
59 views

Angular: scrollIntoView not working on route change without setTimeout in ngAfterViewInit

I have an Angular component where I want to use scrollIntoView when the route changes. Here's the relevant code snippet from my component: @ViewChild('structure') structure: ElementRef | undefined; ...
Apurv's user avatar
  • 1
1 vote
1 answer
42 views

Is the execution of fn in setTimeout(fn, 0) called from the constructor() ensured to happen after angular lifecycle hooks ngOnInit & ngAfterViewInit?

I have the following Angular2 'pseudo' code and I want to keep the user class as simple as possible: // ###### LIB CLASSES ###### @Component() export abstract class Parent { abstract ...
jan dolezal's user avatar
1 vote
3 answers
60 views

SetTimeout does not work with recursion. What am I doing wrong?

I need a function to print numbers from 1 to 10 every ms using recursion. My function prints numbers ​​from 2 to infinity, probably, although the condition for exiting the recursion is written. What ...
Valentina's user avatar
1 vote
1 answer
101 views

Is there a way to fake timers in Jest for the alternate setTimeout from 'timers/promises'?

In my program, I use the alternate setTimeout function (returns a promise, does not take callbacks) from timers/promises to avoid recursively calling the standard setTimeout function. I'm doing some ...
Michael Goldstein's user avatar
0 votes
3 answers
55 views

Unable to Close Child Window Inside setTimeout Callback in JavaScript

I'm encountering an issue with closing a child window inside a setTimeout callback in JavaScript. Despite successfully opening the child window using window.open, I am unable to access the newChild ...
laktherock's user avatar
0 votes
3 answers
146 views

How does one enforce a chron-job to be executed exactly at every possible 5 minute mark (0:00, 0:05, 0:10) regardless of the chron-job's start time?

I have a JavaScript function of chrome extension that I need to run at exact 5-minute intervals, synchronized with the current time. For example, it should run at 5:00, 5:05, 5:10, and so on, ...
Hamed's user avatar
  • 31
0 votes
1 answer
71 views

JavaScript setTimeout not reflecting updated variable value [closed]

I'm encountering an issue with setTimeout function where it doesn't seem to reflect the updated value of a variable. Here's a simplified version of my code: const handleProcessError = (processName, ...
Prashant Kumar's user avatar
-1 votes
2 answers
84 views

Why is do/while looping infinitely after condition was expected to have been met?

Goal: Delay execution of function by at least 1 second. The problem: Instead of a minimum 1 second delay the do {} while loops forever. The steps: After 1 second timer is set to timerLength. If the ...
myNewAccount's user avatar
-1 votes
1 answer
70 views

setTimeout - change duration after click [duplicate]

I have function setTimeout in JS: Interval = 20000; timer = setTimeout(function loop(){ //do something timer = setTimeout(loop, Interval); }, 1); $("#next_button")....
user3446272's user avatar
0 votes
0 answers
30 views

Javascript setTimeout function not working in tests

Essentially, in the onSearch function, when I run tests on my App.tsx, the function passed into setTimeout is not being executed. I used the debugger to see the call stack and how the code executes ...
Elias Rey's user avatar
-1 votes
1 answer
63 views

Order of execution in NodeJS

I have the below code snippet in NodeJS. console.log("START"); setImmediate(() => { console.log("setImmediate 1"); }); setTimeout(() => { console.log("setTimeout 1&...
KK2491's user avatar
  • 498
2 votes
1 answer
63 views

Is it possible that JavaScript setTimeout() fires earlier?

I wrote a utility function to create an async timeout: export function asyncTimeout(timeout: number): Promise<void> { return new Promise(resolve => setTimeout(resolve, timeout)) } I also ...
Mohammad Javad Khademian's user avatar
1 vote
1 answer
104 views

Angular Router Outlet breaking when using setTimeout, angular 17

So I am working on a project and after routing was implemented a component has broken. On one component I have used a promise delay to hold off some DOM manipulation (adding a class to an element) ...
I2obiN's user avatar
  • 309
0 votes
1 answer
73 views

How to execute a function if a loop is taking a long time?

I have an AJAX call, and the result is processed by a callback. This may be real quick, or take some time. If the callback lasts more than 3 seconds, I want to display an image (or a text) that tell ...
Congregator's user avatar
2 votes
3 answers
217 views

Node.js - setTimeout - order of execution

In this code: setTimeout(() => console.log('C'), 100); setTimeout(() => console.log('D'), 0); const t1 = new Date(); while (new Date() - t1 < 500) {/* block for 500ms */} This will log D -&...
lynxx's user avatar
  • 584
2 votes
0 answers
79 views

difference between hiding the image with and without setTimeout

let c = document.querySelector(".imge"); c.addEventListener("dragstart", () => { setTimeout(() => { c.classList.add("hide") }, 0) }) .hide { display: none; } <img src="https://...
Ujjawal's user avatar
  • 61
0 votes
0 answers
38 views

How to use the async function axios into setInteval or setTimeOut?

I tried to send data regularly from react to laravel by using axios into setInterval, but it send an empty array. Here is my code: const consultationTable = useSelector( (state) => state....
Aicha 's user avatar
0 votes
3 answers
53 views

Force nested loop over observables to wait for all

I've read about forkJoin, async, await, and also tried out angular life cycle methods, but finally found no good solution. I need to wait until initiAttributesMap has finished his job before next code ...
saab's user avatar
  • 139
0 votes
2 answers
51 views

Why would my setTimeout() return a random number on screen when the callback function executed

I am trying to learn Svelte by building a quiz app. What I wanted to achieve is that when the user has answered a question from the quiz, it automatically jumps to the next one. I set a setTimeout() ...
Edward's user avatar
  • 59
0 votes
1 answer
86 views

Promise.race not stopping the execution of long running task [duplicate]

Hi in this code block my requirement is to execute the function test() such that it should stop executing ( it was going through an infinite loop and crashing the page) if it takes for than 1 min. I ...
Sourabh Raja's user avatar
0 votes
0 answers
47 views

How can I use setTimeout to handle when a user stops typing? I'm trying to implement typing indicators in a real-time chat app

I'm nearly finished putting together a real-time chat app that uses a Django channels consumer and a React front-end. I've implemented typing indicators in the handleTyping and handleNewChat hook ...
Dan Gray's user avatar
2 votes
0 answers
186 views

How to implement a DuckDB query timeout

I am trying to execute queries on a large duckdb connection that takes user inputs, some inputs may end up taking too long and I am having trouble figuring out how to time out the queries in the event ...
Aman Singh's user avatar
0 votes
1 answer
69 views

How the code execution order works with await in js?

I'm trying to figure out how the code precedence and order is with presence of await, but it seems a little bit confusing, for instance I have code below: const a = Promise.resolve(98); const b = ...
lome1446's user avatar
2 votes
1 answer
115 views

RxJS setTimeout operator equivalent

Is there a RxJS operator that can replace set/clearTimeout in this specific case: this.mouseEnterSubscription = this.mouseEnterStream .subscribe(() => { this.timeout = setTimeout(() => { ...
AlexBor's user avatar
  • 295
0 votes
1 answer
55 views

Change detection in Angular for timers

I was going through the Angular source code trying to find out how change detection is triggered for timers. I know they are patched, but I can't find a place where the actual change detection is ...
AlexBor's user avatar
  • 295
0 votes
1 answer
39 views

Why 3 setTimeout funcs were executed at the same time (as macrotasks)?

setTimeout is a macrotask right? And event loop executes only 1 macrotask in 1 "tick", as far as I understand. So, why does it look like these functions were executed in one "tick" ...
AlxCtchr's user avatar
0 votes
1 answer
63 views

Wrapping setTimeout in a promise

I have read all of the similar questions about this on this site and can't seem to figure out exactly how to make setTimeout work with promises/await for my use case. I am using discord.js v14 and ...
Mythic-ctrl's user avatar
0 votes
0 answers
51 views

Safari open.window has no effect with a delay bigger than 300ms

I want to open a new blank page in Safari after a while when a button click event is fired. $( "#btn" ).on( "click", function() { setTimeout(() => { window.open("...
Tiago Barroso's user avatar
-1 votes
2 answers
30 views

JS - many setTimeout takes longer than expected

I'm working on some projects and I was wondering why the setTimeout(s) I was delaying where taking a lot longer then expected... To give a context, the code reacts to some triggers, and the function ...
Ren's user avatar
  • 155
0 votes
1 answer
57 views

setTimeout triggered with different delays

Inside a method in an Angular App, I need to invoke a setTimeout to solve some layout issues with a 3rd party UI library: setStep(): void { // This is a workaround to fix the current UI issue. ...
Francesco's user avatar
  • 10.7k
0 votes
0 answers
16 views

Why is this timing function getting a typeError? [duplicate]

The timer stops when the mouse hovers over a (.typing) item and the timer resumes when the mouse leaves. That works, but I wanted to remove two classes from separate id's when their respective ...
Clint Strong's user avatar
-1 votes
2 answers
49 views

why throw inside of an setTimeout, located inside a promise, doesn't change state and result of the output promise? [duplicate]

I know existence of a throw inside of a promise, change the state of that specific promise to rejected and the result will be the error message, but when I type this throw inside of a setTimeout ...
lome1446's user avatar

1
2 3 4 5
108