Created
October 24, 2017 09:15
-
-
Save akatov/c75ddf545a79b1c313d19a5354b9bcbc to your computer and use it in GitHub Desktop.
ember-concurrency experiments
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'; | |
const WAIT_HERE_FOREVER = Ember.RSVP.defer().promise; | |
export default Ember.Controller.extend({ | |
count: 0, | |
mostRecent: null, | |
myTask: task(function * () { | |
try { | |
this.incrementProperty('count'); | |
yield timeout(1000); | |
console.log('rest of try'); | |
} catch (e) { | |
console.log('catch'); | |
throw e; | |
} finally { | |
// finally blocks always get called, | |
// even when the task is being canceled | |
console.log('finally'); | |
this.decrementProperty('count'); | |
} | |
}), | |
actions: { | |
performTask() { | |
let task = this.get('myTask'); | |
let taskInstance = task.perform(); | |
this.set('mostRecent', taskInstance); | |
}, | |
cancelAll() { | |
this.get('myTask').cancelAll(); | |
}, | |
cancelMostRecent() { | |
this.get('mostRecent').cancel(); | |
}, | |
} | |
}); |
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, taskGroup, timeout } from 'ember-concurrency'; | |
function * taskFn() { | |
try { | |
console.log('starting try'); | |
console.log('yeah'); | |
yield timeout(2000); | |
console.log('finishing try'); | |
} catch(e) { | |
console.log('catch'); | |
throw e; | |
} finally { | |
console.log('finally'); | |
} | |
} | |
export default Ember.Controller.extend({ | |
chores: taskGroup().restartable(), | |
mowLawn: task(taskFn).group('chores'), | |
doDishes: task(taskFn).group('chores'), | |
changeDiapers: task(taskFn).group('chores'), | |
tasks: Ember.computed(function() { | |
return [ | |
this.get('mowLawn'), | |
this.get('doDishes'), | |
this.get('changeDiapers'), | |
]; | |
}), | |
}); |
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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('task-groups'); | |
this.route('cancellation'); | |
}); | |
export default Router; |
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
{ | |
"version": "0.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-concurrency": "0.8.10" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment