Last active
October 17, 2018 13:48
-
-
Save shyshy/d2393787d9fe734184887108b7415954 to your computer and use it in GitHub Desktop.
ember-concurrency finally
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'; | |
import { run } from '@ember/runloop'; | |
export default Ember.Controller.extend({ | |
runs: [], | |
test: task(function*() { | |
const id = Math.floor(Math.random() * 1000); | |
// yield timeout(1); | |
try { | |
this.get('runs').pushObject({ id, message: 'try' }); | |
yield timeout(3000); | |
} finally { | |
this.get('runs').pushObject({ id, message: 'finally' }); | |
} | |
this.get('runs').pushObject({ id, message: 'completed' }); | |
}).restartable(), | |
actions: { | |
test() { | |
this.get('test').perform(); | |
}, | |
clear() { | |
this.get('test').cancelAll(); | |
run.later(() => { this.get('runs').clear(); }, 1); | |
} | |
} | |
}); | |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2", | |
"ember-concurrency": "0.8.22" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment