5,374 questions
Best practices
0
votes
3
replies
72
views
Using setTimeout within useEffect() to debounce searching in react native pagination
I am planning to implement pagination into my project for my data from Supabase, I had the idea that since there are different parameters (such as search text, page number, filter) that I should use ...
1
vote
3
answers
92
views
White page when I use setTimeout
I created an intro/splash screen component that should display for 5 seconds and then automatically navigate to the login page.
The strange thing is:
If I don’t use setTimeout, Angular correctly ...
2
votes
1
answer
149
views
Why does setTimeout execute before fetch .then despite microtask priority? [duplicate]
I'm running the code below. The output I was expecting was:
Start -> End -> While expires -> joke -> setTimeout
However, the output I’m actually getting is:
Start -> End -> While ...
0
votes
0
answers
53
views
Why does setTimeout inside a loop print the same value? [duplicate]
I'm trying to understand how setTimeout works inside a loop in JavaScript. I expected it to print numbers from 1 to 5, each printed after one second, but instead, it prints the number 6 five times.
...
0
votes
0
answers
35
views
Why does "let" behave differently from "var" inside a for loop with "setTimeout"? [duplicate]
I’m trying to understand the difference in behavior between let and var inside a for loop, especially when used with setTimeout.
Here’s a simple example:
for (var i = 0; i < 3; i++) {
setTimeout((...
2
votes
3
answers
104
views
Delaying 2 setIntervals using setTimeout doesn't work
I've been writing a userscript for a site and I want to show an update notification while the user is tabbed off of the site, and I came up with an idea to use the site title for that.
This is my ...
0
votes
1
answer
88
views
Why is my custom error handler not caching throws inside setTimeout inside runOutsideAngular
I have an Angular App with a custom error handler which works fine.
Errors like these are caught:
throw new Error('This error gets passed to the custom error handler');
this.zone.runOutsideAngular(() ...
0
votes
1
answer
72
views
missing letters when using a Typewriter effect hook - React
I have a piece of code which needs to be rendered using a typewriter effect. Basically, they are API responses similar to a GPT app. The code I have does the trick but while rendering the first case, ...
-1
votes
1
answer
138
views
How to handle an slow request of Stripe webhook?
Following the Stripe documentation I come to create a webhook endpoint on my app to catch the customer.subscription.created event, which I use as a signal to create a new account in my database.
I'm ...
0
votes
1
answer
93
views
Devtools console: Function was resolved from bound function
Browsers have a window.stop() function which I have overwritten for my own purposes:
window.stop = (s,t,o,p=window) => { ... };
I'm trying to troubleshoot why calling my stop() function does not ...
0
votes
2
answers
94
views
Loop through a state array in React and switch each item to true using setTimeout
I have an array in state:
const [show, setShow] = useState([false, false, false, false])
These affect whether or not an image is displayed.
I'd like to iterate through them one by one, using a delay ...
1
vote
0
answers
54
views
Socket.io code snippet explained (JavaScript setTimeout and function.apply)
I have two questions regarding the following socket.io code snippet:
const withTimeout = (onSuccess, onTimeout, timeout) => {
let called = false;
const timer = setTimeout(() => {
if (...
1
vote
0
answers
39
views
Are timers in Node.js part of event-driven architecture? Do they emit events when they expire?
I was wondering if timers are actually part of event-driven architecture in Node.js.
However, I haven't found anything mentioning it in the official Node.js documentation.
Does it actually emit any ...
0
votes
0
answers
34
views
worker-timers package callback fires immediately after deep sleep, ignoring intended delay
I’m using the worker-timers npm package in a Vue 3 + TypeScript application to implement a lock/unlock mechanism of notes using Ably (where the notes are shared between multiple users). The idea is ...
0
votes
0
answers
66
views
When WKWebView is inactive in iOS, settimeout cant work
When A WebViewController push B WebViewController, the settimeout function in A WebViewController will be stop working until returning to A WebViewController.
On a PC, switching tabs in a WebView does ...
0
votes
1
answer
65
views
Delayed function execution of setInterval
I'm trying to delay the execution of the setInterval function, which is set at 2000.
Ideally, I would like the function to be executed after 10000 at every refresh of the page + after each hide on ...
0
votes
2
answers
84
views
Timeout exception with selenium and python. What is wrong with this navigation?
the idea of the code is simple. It will go to the search's page, "see" all the products there, click one by one, scrape all the data, go back to the search's page and click on the next ...
2
votes
1
answer
125
views
Javascript loop to wait for input from external source (Android tasker)
I am having a hard time with wait loops in JavaScript to wait for content from an external source (tasker).
In particular I have an HTML document with JavaScript (shown in a WebView element inside a ...
0
votes
0
answers
46
views
How to prevent individual component timeouts from overlapping?
I am trying to handle individual promises in a React app, and list their current state in a list on the App.
I have two components :
InstructionList : has the job to show and update a list of <...
0
votes
0
answers
70
views
Dynamically loading audio from the backend and playing it on the website
There is a website, it is connected to the OpenAI Speech API on the server, the server accepts a POST request from the frontend, which contains the text that needs to be voiced, the API voices it and ...
0
votes
1
answer
220
views
rAF loop for consistent requestAnimationFrame precision and timing
I have found contradicting information regarding timing with requestAnimationFrame in JS and would appreciate some help. In this post (1 Exact time of display: requestAnimationFrame usage and timeline)...
0
votes
0
answers
89
views
How to wait for media element source to actually update with Async/Await?
I am using vanilla JS, webaudioAPI and canvas elements to create an audio visualizer.
When I update the audio element src with javascript, I need the audio element duration property to update two ...
0
votes
3
answers
155
views
Why setTimeout is executing this way
Code:
setTimeout(() => console.log("1"), 1000)
const startTime = Date.now()
while (Date.now() - startTime < 5000);
setTimeout(() => console.log("2"), 0)
setTimeout(() => console.log("...
-2
votes
1
answer
82
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');
...
0
votes
0
answers
141
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. ...
0
votes
0
answers
54
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',
...
0
votes
1
answer
50
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 ...
0
votes
1
answer
83
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 ...
0
votes
0
answers
36
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 (...
0
votes
1
answer
131
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 ...
-1
votes
1
answer
114
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 ...
1
vote
1
answer
96
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)....
0
votes
0
answers
68
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
...
1
vote
3
answers
51
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', '...
-1
votes
2
answers
108
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....
0
votes
1
answer
166
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;
...
1
vote
1
answer
52
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 ...
1
vote
3
answers
74
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 ...
2
votes
1
answer
424
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 ...
0
votes
3
answers
72
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 ...
0
votes
3
answers
174
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, ...
0
votes
1
answer
92
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, ...
-1
votes
2
answers
99
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 ...
-1
votes
1
answer
111
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")....
-1
votes
1
answer
143
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&...
2
votes
1
answer
65
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 ...
1
vote
1
answer
147
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) ...
0
votes
1
answer
78
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 ...
2
votes
3
answers
266
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 -&...
2
votes
0
answers
86
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://...