Skip to content

Instantly share code, notes, and snippets.

@MartinMalinda
Last active August 8, 2020 13:06
Show Gist options
  • Save MartinMalinda/577841db4a3cc64d43d2c9d5be64c1a8 to your computer and use it in GitHub Desktop.
Save MartinMalinda/577841db4a3cc64d43d2c9d5be64c1a8 to your computer and use it in GitHub Desktop.
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