Last active
August 29, 2015 14:19
-
-
Save francisbrito/41a4569dd0181d999a74 to your computer and use it in GitHub Desktop.
Task concept.
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
var getProductsPromise = Promise.resolve(['banana', 'apple', 'pear']); | |
var _do = function (promise) { | |
var resolved = false, | |
value = null, | |
err = null; | |
promise.then((result) => { | |
value = result; | |
resolved = true; | |
}) | |
.catch((error) => err = error); | |
while (!resolved) {} | |
if (err) { | |
throw err; | |
} | |
return value; | |
}; | |
// I'd like to do this: | |
try { | |
var products = _do(getProductsPromise); | |
console.log('from task: ', products); | |
} catch (err) { | |
throw err; | |
} | |
// Instead of this: | |
getProductsPromise | |
.then(function (products) { | |
console.log('from callbacks: ', products); | |
}) | |
.catch(function (err) { | |
throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment