Skip to content

Instantly share code, notes, and snippets.

@francisbrito
Last active August 29, 2015 14:19
Show Gist options
  • Save francisbrito/41a4569dd0181d999a74 to your computer and use it in GitHub Desktop.
Save francisbrito/41a4569dd0181d999a74 to your computer and use it in GitHub Desktop.
Task concept.
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