I have tried finding an answer but they aren't exactly similar to the situation I'm in and I don't know how to apply them. I'm trying to run a function for only 233ms, but I don't know how to do this (sorry im a noob and just started java script). How would I do this?
Asked
Active
Viewed 360 times
-2
-
3Does this answer your question? [How to implement a "function timeout" in Javascript - not just the 'setTimeout'](https://stackoverflow.com/questions/8778718/how-to-implement-a-function-timeout-in-javascript-not-just-the-settimeout) This sounds like an XY problem, what's the actual issue you're trying to solve? – SuperStormer Feb 22 '21 at 00:10
-
1If the timing has to be accurate then Javascript is not the tool to use. – Tangentially Perpendicular Feb 22 '21 at 00:11
-
1What does the function do? Why does it take so long? Are you trying to limit the execution time of a function, or are you trying to repeat the execution so that it takes 233ms? – Bergi Feb 22 '21 at 00:11
-
You should show your existing cod and explain why it doesn't work. – user202729 Feb 22 '21 at 00:18
1 Answers
-1
You could do a setTimeout for 233ms then have it clear the function from working when it is done.
setTimeout tutorial here https://www.w3schools.com/jsref/met_win_settimeout.asp

GtiClicker
- 78
- 8
-
Can you upvote and check as the answer (the checkmark) if it helped that would be appreciated. – GtiClicker Feb 22 '21 at 00:16
-
Setting the timeout is one thing. How do you propose to interrupt the function when the timeout expires? – Tangentially Perpendicular Feb 22 '21 at 02:50