Skip to content

Instantly share code, notes, and snippets.

@vincentbello
Created October 8, 2016 20:28
Show Gist options
  • Save vincentbello/69b0e9ec9d2006839f4c63fcd8b52a21 to your computer and use it in GitHub Desktop.
Save vincentbello/69b0e9ec9d2006839f4c63fcd8b52a21 to your computer and use it in GitHub Desktop.
products/product-overview.js
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Component.extend({
// Periodically refresh product info on init
_reloadDataTask: task(function * () {
while (true) {
yield timeout(30 * 1000); // Wait 30 seconds
if (this.get('product')) {
yield this.get('product').reload();
}
}
}).on('init'),
actions: {
// Cancel the periodic data reload task
cancelReloadTask() {
this.get('_reloadDataTask').cancelAll();
},
// Restart the periodic data reload task
restartReloadTask() {
this.get('_reloadDataTask').perform();
},
},
});
@curtu
Copy link

curtu commented Sep 11, 2018

I have read your very good post and i have a question. Did you have an code example of what you said here ?

we store two task instances in our model, one for the current data request, and one for the last performed data request for this same model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment