// Polls the server state until it's our turn. async function poll() { // Keep polling the server while the game state could change remotely. while (game.state.progress == "playing" && !game.yourturn) { await sleep(1000); response = await fetch('/game'); await updateGame(response) } } // Returns a promise that waits ms milliseconds. function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }