|
|
|
|
|
by angersock
3623 days ago
|
|
So, I think an example here will help you understand. Let's use NodeJS with Express and with pg-node. Let's say you have a database. 1. You define an Express handler to handle a get request.
2. In that handler, you connect to a database, which takes a callback
3. You create a query on that connection, this takes a callback.
4. You then write a function that feeds the query result rows into a CSV exporter, which takes a callback (because of course it does).
You now have a pyramid something like 5 levels deep. Callback hell is in fact a thing.However, I've found that pipeline of promises almost completely solve that problem. |
|
I mean if I didn't have the option of using promises, I would have probably written something like this.
function handler(callback){