Last active
December 20, 2016 17:05
-
-
Save jyotman/0fcf0ce4298760854b99a13f53e17dd7 to your computer and use it in GitHub Desktop.
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
'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