Last active
August 8, 2020 13:06
-
-
Save MartinMalinda/577841db4a3cc64d43d2c9d5be64c1a8 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
import { useTask, timeout } from 'vue-concurrency; | |
export default defineComponent({ | |
setup() { | |
const weatherData = ref(null); | |
const pollTask = useTask(function*() { | |
while (true) { | |
weatherData.value = yield ajax('/api/weather'); | |
yield timeout(5000); // wait 5s | |
} | |
}).drop(); | |
pollTask.perform(); | |
return { pollTask, weatherData, pause, resume }; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment