Last active
August 29, 2015 14:27
-
-
Save shidhincr/81416225d2cbbacd60e7 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
var greeting; | |
var readGreetingFromFileSync = function(){ | |
return 'Hello, '; | |
}; | |
var getUserId = function(){ | |
return new Promise(function(resolve){ | |
setTimeout(function(){ | |
resolve(2); | |
},100); | |
}); | |
}; | |
var getUserFullName = function(id){ | |
var map = { | |
1: 'shidhin', | |
2: 'some one' | |
}; | |
return new Promise(function(resolve,reject){ | |
setTimeout(function(){ | |
resolve(map[id]); | |
},1000); | |
}); | |
}; | |
var displayGreeting = function(name){ | |
console.log(greeting+name); | |
}; | |
getUserId() | |
.then(getUserFullName) | |
.then(displayGreeting) | |
.then(function(){ | |
console.log('The greeting was: ', greeting); | |
}); | |
greeting = readGreetingFromFileSync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment