Created
April 27, 2018 09:53
-
-
Save andreasvirkus/39de98bffb8a6ae89649fa6f05777d6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *pollForWeatherInfo(){ | |
while (true) { | |
yield fetch('/api/currentWeather', { | |
method: 'get' | |
}).then(res => res.json()) | |
} | |
} | |
function runPolling(generator){ | |
if (!generator) { | |
generator = pollForWeatherInfo() | |
} | |
const p = generator.next() | |
p.value.then(d => { | |
if (!d.temperature) { | |
runPolling(generator) | |
} else { | |
console.log(d) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment