Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created April 27, 2018 09:53
Show Gist options
  • Save andreasvirkus/39de98bffb8a6ae89649fa6f05777d6a to your computer and use it in GitHub Desktop.
Save andreasvirkus/39de98bffb8a6ae89649fa6f05777d6a to your computer and use it in GitHub Desktop.
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