Last active
August 29, 2015 14:01
-
-
Save eoinkelly/6f2ac54630ad14119de2 to your computer and use it in GitHub Desktop.
A test-drive of the Ember Inspector promises tab
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
// # How to use this: | |
// | |
// 1. Open the Ember Inspector on an Ember app (so Ember is loaded) | |
// 2. Hit the 'clear' button on the Promises tab to remove any promises from the app itself | |
// 3. Paste this code into the console and watch how the promises inspector displays it | |
// 4. Twiddle, Rinse & repeat | |
// 5. More info at | |
// * https://github.com/kriskowal/q/blob/v1/design/README.js (great for understanding promises) | |
// * http://emberjs.com/api/classes/Ember.RSVP.Promise.html (Ember promise implementation specifics) | |
// ========================== | |
// Ember.RSVP.Promise(resolverFunction, label) | |
var p1 = new Ember.RSVP.Promise(function(resolve, reject) { | |
var val = "I am some vital data"; | |
// simulate a slow server | |
setTimeout(function () { | |
resolve(val); | |
}, 5000); | |
// THIS WILL NEVER FAIL! | |
// but if it did ... | |
// var reason = new Error('The thing that should not be'); | |
//reject(reason); | |
}, "Pulling vital data from the Internets"); | |
// .then(resolveCallback, rejectCallback, label) | |
var p2 = p1.then( | |
function (p1val) { | |
return p1val + " (has been validated)"; | |
}, | |
function (p1err) { | |
// handle error from the operation that created p1 | |
}, | |
"Running spooky validations on it from a distance" | |
); | |
var p3 = p2.then(function (p2val) { | |
return p2val + " (has been converted)"; | |
}, null, "Converting it for use in our app") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment