Forked from Gaurav0/components.press-and-hold-button.js
Last active
April 17, 2016 18:30
-
-
Save hakilebara/2e292b9b57a79849b366958e3223dcaa to your computer and use it in GitHub Desktop.
Ember Concurrency Test
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 { task, timeout, all, race } from 'ember-concurrency'; | |
const methods = { all, race }; | |
export default Ember.Controller.extend({ | |
status: "Waiting...", | |
childTasks: null, | |
parent: task(function * (methodName) { | |
let allOrRace = methods[methodName]; | |
let childTasks = []; | |
for (let id = 0; id < 5; ++id) { | |
childTasks.push(this.get('child').perform(id)); | |
} | |
this.set('childTasks', childTasks); | |
this.set('status', "Waiting for child tasks to complete..."); | |
let words = yield allOrRace(childTasks); | |
this.set('status', `Done: ${Ember.makeArray(words).join(', ')}`); | |
}).restartable(), | |
child: task({ | |
percent: 0, | |
id: null, | |
perform: function * (id) { | |
this.set('id', id); | |
while (this.percent < 100) { | |
yield timeout(Math.random() * 100 + 100); | |
let newPercent = Math.min(100, Math.floor(this.percent + Math.random() * 20)); | |
this.set('percent', newPercent); | |
} | |
return `Task_${id}`; | |
}, | |
}).maxConcurrency(3), | |
actions: { | |
cancel(task) { | |
task.cancel(); | |
} | |
} | |
}); |
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
{ | |
"version": "0.7.2", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js", | |
"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