I’ve got a javascript loop that triggers every time the page receives an update via websocket. This loop persists usually even after the next websocket update is received. The result is multiple loops begin running and page performance degrades rapidly. Each loop is critical though and only becomes obsolete until the next update.
Is there a way to terminate an active loop from another function or am I plainly just thinking about this the wrong way?
Usually you would set a flag/condition outside of the loop that get’s checked on every iteration.
So..
In your case I think what you could have is a queue of updates. So your loop would check the queue – see that it has four updates since it last did it’s thing – then it does whatever it does. New websocket updates come in – loop finishes what it was doing – comes back and checks the queue again.