Skip to content

Instantly share code, notes, and snippets.

@shidhincr
Last active August 29, 2015 14:27
Show Gist options
  • Save shidhincr/81416225d2cbbacd60e7 to your computer and use it in GitHub Desktop.
Save shidhincr/81416225d2cbbacd60e7 to your computer and use it in GitHub Desktop.
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