I have an XHR-Request returning an OAuth2 Token. I want my code to wait until i received that token (or received 401 or something like that) and then go on. Sadly i found out that there is nothing like "Thread.sleep" in JavaScript. What is the best way to wait for XHR-Requests to finish before going on with the code?
My code uses the onreadystatechange-function of the XHR-Object (so the other code will go on while the request is still executing). My method is invoked and should return the token, so i can't just go with the
if ((status===200) && (readyState===4))
condition.