Skip to main content

Posts

Showing posts from April, 2017

Promises in Nodejs

Promises are a method by which we can handle Asynchronous Requests in a better way. Normally a Promise has three output conditions: a. RESOLVED b. PENDING c. REJECT Just imaging a Promise that your father made, for buying a good phone. It would have three conditions: a. RESOLVED - Your father got you a new phone. b. REJECTED - You didn't got a new phone. c. PENDING - The promise is neither rejected or fulfilled, still you are waiting for the phone function checkValue ( x ){ if ( x > 100 ){ return Promise . resolve ( x ); } else { return Promise . reject ( "does not satisfy the condition" ); } } var result = checkValue ( 20 ); console . log ( "this is executing" ); console . log ( result ); //This returns an Object of Promise which we can use. var t = function (){ //The object of Promise can be used to use Then or use Catch for the Error. result . then ( function ( fulfi