Last active
May 18, 2018 22:39
-
-
Save maxfierke/e62be2d9ce7d72a92480d27b4ebb3865 to your computer and use it in GitHub Desktop.
e-c vs e-c-retryable return erroring promise
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, all } from 'ember-concurrency'; | |
import { retryable, DelayPolicy } from 'ember-concurrency-retryable'; | |
import RSVP from 'rsvp'; | |
const delayPolicy = new DelayPolicy({ delay: [100, 100] }); | |
const originalEmberOnError = Ember.onerror; | |
let defers = []; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
regularWithoutYield: task(function * () { | |
return all([ | |
this.get('unlinkedTask').unlinked().perform(), | |
this.get('anotherUnlinkedTask').unlinked().perform(), | |
this.get('regularTask').perform(), | |
this.get('throwingTask').perform(), | |
]); | |
}).drop(), | |
regularWithYield: task(function * () { | |
return yield all([ | |
this.get('unlinkedTask').unlinked().perform(), | |
this.get('anotherUnlinkedTask').unlinked().perform(), | |
this.get('regularTask').perform(), | |
this.get('throwingTask').perform(), | |
]); | |
}).drop(), | |
retryableWithoutYield: retryable(task(function * () { | |
return all([ | |
this.get('unlinkedTask').unlinked().perform(), | |
this.get('anotherUnlinkedTask').unlinked().perform(), | |
this.get('regularTask').perform(), | |
this.get('throwingTask').perform(), | |
]); | |
}).drop(), delayPolicy), | |
retryableWithYield: retryable(task(function * () { | |
return yield all([ | |
this.get('unlinkedTask').unlinked().perform(), | |
this.get('anotherUnlinkedTask').unlinked().perform(), | |
this.get('regularTask').perform(), | |
this.get('throwingTask').perform(), | |
]); | |
}).drop(), delayPolicy), | |
unlinkedTask: getDeferableTask('unlinkedTask'), | |
anotherUnlinkedTask: getDeferableTask('anotherUnlinkedTask'), | |
regularTask: getDeferableTask('regularTask'), | |
throwingTask: task(function* () { | |
yield timeout(100); | |
throw new Error('This task throws'); | |
}), | |
actions: { | |
async catchATask(name) { | |
this.set(`${name}CaughtError}`, null); | |
this.set(`${name}EmberOnError`, null); | |
defers = []; | |
Ember.run.later(() => { | |
defers.shift().resolve('a'); | |
}, 300); | |
Ember.run.later(() => { | |
defers.shift().resolve('b'); | |
}, 700); | |
Ember.run.later(() => { | |
defers.shift().resolve('c'); | |
}, 1000); | |
Ember.onerror = (e) => { | |
console.log(e); | |
this.set(`${name}EmberOnError`, true); | |
}; | |
try { | |
await this.get(name).perform(); | |
} catch (e) { | |
this.set(`${name}CaughtError`, true); | |
} | |
} | |
} | |
}); | |
function getDeferableTask(name) { | |
return task(function * () { | |
let defer = RSVP.defer(); | |
defers.push(defer); | |
let value = yield defer.promise; | |
return value; | |
}); | |
} |
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.16.0", | |
"ember-template-compiler": "2.16.0", | |
"ember-testing": "2.16.0" | |
}, | |
"addons": { | |
"ember-concurrency": "latest", | |
"ember-concurrency-retryable": "latest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment