Playing with Promises

in NodeJS

Either writing Javascript or NodeJS, we are always dealing with an asynchronous approach. We have to be very careful while implementing in this environment and also chanining callbacks will make your code not readable at all. - Even for yourself :) - General saying about this is Pyramid of Doom or Callback Hell

Let me give you an example - a developers day;

Pyramid of Doom or Callback Hell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
wakeup(function(alarm, callback) {
haveBreakfast(function(eggs) {
gotoOffice(function(car) {
writeCode(function(scrum, meeting, task) {
haveLunch(function(whereToEat) {
writeMoreCode(function(moretasks) {
gobackHome(function(car) {
haveDinner(function(isItReady) {
watchTV(function(phew) {
return calback('done with the day'));
})
})
})
})
})
})
})
})
})
Continue reading
  • page 1 of 1
Author's picture

Volkan N. Metin

Father of 2 beautiful kids
Computer Engineer
Software Development Adventurer


Software Development Manager


Istanbul, TR