Skip to main content
Promises 
Never gonna give you up 
Never gonna let you down 
Never gonna tell a lie and hurt you 
Created by Jason Sich / @jasich
What is a promise? 
A promise is an object that represents the result of an asychronous 
operation, which may or may not have happened. They provide 
methods for control flow to handle the callback of an asynchronous 
operation.
Why would you want that? 
So that you can start returning data from your functions instead of 
injecting high-level code into low-level code (callbacks).
Why would you want that? 
(cont...) 
Consider how much more powerful it is to return results to high level 
code, rather than injecting functionality into low-level code. 
You get more... 
Control 
Flexibility 
Better Code Readability
Terminology 
Resolution 
Promises only get resolved once 
resolved - Async operation has occurred 
unresolved - Async operation has NOT occurred YET 
Fulfillment 
fulfilled - When a promise is resolved successfully 
rejected - When a promise is NOT resolved successfully 
Other 
thenable - You can chain any function that returns a value after the 
initial then
How do I promise? 
Well they aren't quite native in node yet (in beta). But there are many 
npm packages that allow you to use them. 
q promise 
node-promise 
When looking at promise libraries try to get something that conforms to 
the Promises/A+ spec
Control Flow 
Promises provide methods for control flow. 
then() 
catch() 
done() 
others 
names/availability depend on spec implementation
Examples 
https://github.com/jasich/promisesPresentation/tree/master/src
The End 
Created by Jason Sich 
@jasich on Twitter 
jasich on GitHub