Skip to content

Instantly share code, notes, and snippets.

@hakilebara
Last active April 17, 2016 18:59
Show Gist options
  • Save hakilebara/48dead207a2cd3e22be5adeeb18e4303 to your computer and use it in GitHub Desktop.
Save hakilebara/48dead207a2cd3e22be5adeeb18e4303 to your computer and use it in GitHub Desktop.
ember-concurrency__001
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
status: "Waiting to start",
parentTask: task(function * () {
this.set('status', "1. Parent: one moment...");
yield timeout(1000);
let value = yield this.get('childTask').perform();
this.set('status', `5. Parent: child says "${value}"`);
yield timeout(1000);
this.set('status', "6. Done!");
}).restartable(),
childTask: task(function * () {
this.set('status', "2. Child: one moment...");
yield timeout(1000);
let value = yield this.get('grandchildTask').perform();
this.set('status', `4. Child: grandchild says "${value}"`);
yield timeout(1000);
return "What's up";
}),
grandchildTask: task(function * () {
this.set('status', "3. Grandchild: one moment...");
yield timeout(1000);
return "Hello";
}),
actions: {
cancel(task) {
task.cancel();
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<h5>{{status}}</h5>
<ul>
<li>Parent Task: {{parentTask.state}}</li>
<li>Child Task: {{childTask.state}} <button {{action "cancel" childTask}}>Cancel</button></li>
<li>Grandchild Task: {{grandchildTask.state}}</li>
</ul>
<button onclick={{perform parentTask}}>
{{#if parentTask.isRunning}}
Restart Parent Task
{{else}}
Perform Parent Task
{{/if}}
</button>
<br>
<br>
{
"version": "0.8.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.5.0",
"ember-data": "2.5.1",
"ember-template-compiler": "2.5.0",
"babel-polyfill":"https://cdn.rawgit.com/nicksrandall/babel-polyfill/master/browser-polyfill.js"
},
"addons": {
"ember-concurrency": "0.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment