A promise in JavaScript is an abstraction around the idea of an asynchronous callback that supports chaining. This makes the code read to the humans like it is procedural. Do step #1 then step #2 then step #3 all while allowing the computer to handle all the asynchronicity in the all the calls.
It turns this code...
doAsyncThing(input,function(result){doAnotherAysncThingUsingResult(result,function(anotherResult){doFinalAsyncThing(anotherResult,function(finalResult){console.log("It is finished: ",finalResult);});});});
...into this code.
doAsyncThing(input).then(result=>doAnotherAysncThingUsingResult(result)).then(anotherResult=>doFinalAsyncThing(anotherResult)).then(finalResult=>console.log("It is finished: "", finalResult));
I blogged about this a few months ago on my company's blog here.
A promise in JavaScript is an abstraction around the idea of an asynchronous callback that supports chaining. This makes the code read to the humans like it is procedural. Do step #1 then step #2 then step #3 all while allowing the computer to handle all the asynchronicity in the all the calls.
It turns this code...
...into this code.
I blogged about this a few months ago on my company's blog here.
Thank you Guy !! that was a neat and simple explanation.