This function below doesn’t work like i want it to;Being a js novice i can’t figure out why.I need it to wait 5 seconds before checking whether the newstate is -1.Currently, it doesn’t wait, iThere are several ways of doing this, but why do you need to add a delay?If we knew then we'd be able to suggest the most appropriate way to do it.To add to this answer:
Definition & Meaning of
Definition & Meaning of "Waiting" | LanGeek

Definition & Meaning of "Waiting" | LanGeek of Wait, Simpcity Cutiegothxo Is PREGNANT?! The Rumors Are Flying! .

40
By 
Executing the command (su ) in the background and immediately wait ing for it can be useful when using set -e and writing conditions whose code should still have set -e in place …What is the difference between a wait() and sleep() in threads?Is my understanding that a wait() -ing thread is still in running mode and uses cpu cycles but a sleep() -ing does not consume any cpu …If you want a no busy wait for lua for use in frames for videogames or applications, perhaps wxlua or other libraries may provide less resource craving sleep functions.The sleep function i provide is …