Skip to content

Instantly share code, notes, and snippets.

@jyotman
Last active December 20, 2016 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyotman/0fcf0ce4298760854b99a13f53e17dd7 to your computer and use it in GitHub Desktop.
Save jyotman/0fcf0ce4298760854b99a13f53e17dd7 to your computer and use it in GitHub Desktop.
'use strict';
function square(num) {
return new Promise(function(resolve, reject) {
if (num > 10)
reject('Yo error bro!');
else
setTimeout(function() { resolve(num * num) }, 2000);
});
}
async function caller2(num) {
try {
const ans = await square(num);
return ans;
} catch (err) {
console.log('Error in caller2 = ', err);
return Promise.reject(err);
}
}
async function caller1(num) {
try {
const ans = await caller2(num);
console.log('Ans received = ', ans);
} catch (err) {
console.log('Error in caller1 = ', err);
}
}
caller1(11);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment