This is the intro to promises I wish I had before reading all the currently
available intro to promises
Not enough focus on the core promise concept, a library (and a library
specic API) is introduced before all the concepts are explained: except
for this article:
http://robotlolita.me/2015/11/15/how-do-promises-work.html
Now that we have a Promise Spec, we can start writing promises lean
and native without a library specic API
As a programming concept :
A promise represents the eventual result of an asynchronous operation
As a ECMA Specication :
We nally have a Promise Specication and several implementations
ES6s native promise have adopted the Promise/A+ Spec:
https://promisesaplus.com/
1. Flattened callbacks
2. Return values from asynchronous function
3. Throw and Catch exceptions
For a Promise to make (2) and (3) work, the asynchronous function itself
should return a Promise Object. This Promise object has two methods,
then and catch. The methods will later be called depending on the state
(fulled || rejected) of the Promise Object.
Lets see that again with a core node function like fs.readFile()