From Callback Hell to AsyncHeaven – Promises!
A Play in Three Acts:Inferno, Purgatorio, and Paradiso
THE ROAD TO HELL IS PAVED WITH GOOD INTENTIONS
Act I: Inferno
Our Journey Begins
Focusing on the Main Code
The Good and the Bad
SimpleReadableDebuggable
Holds the Thread!Not Async!
SO HOW DO WE RELEASE THE THREAD?
Callbacks!
CALLBACKS
Good Intentions
Doesn’t Look to Bad…
The Pyramid of Doom!
Our Code, In Hell
In Callback Hell, There are no Loops!
BUT I PROMISE – IT GETS BETTER
Act II: Purgatorio
Promises Instead of Callbacks
Chaining Promises
Easy Concurrency
ES6!
So How Do We Write promisedOpen?
Yes, But How do Promises Work?
• I don’t know
• And if I try to understand, my head hurts
• I just learn to accept it
Generalizing promisedOpen Across All Node Functions
ES6!
So Where Does This Take Us?
Ugh…
Still no loop
PROMISES MUST BE KEPT –ONWARD TO ASYNC HEAVEN!
Act III: Paradiso
BUT LET’S YIELD TO A LITTLE DETOUR
Generator Functions
Iterator Protocol
We could have done it like this…
ES6!
But the ES6 compiler does it like this…
Bi-Directional Protocol
THIS IS WHERE IT BECOMESMIND-BOGGLING
Can We Fulfill The Promise?
So What About This?
And… Async Heaven!
From Callback Hell
Our Journey is Complete
Thank You
https://github.com/giltayar/callback-to-async-presentation