Created
October 8, 2016 20:28
-
-
Save vincentbello/69b0e9ec9d2006839f4c63fcd8b52a21 to your computer and use it in GitHub Desktop.
products/product-overview.js
This file contains 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 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(); | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have read your very good post and i have a question. Did you have an code example of what you said here ?