-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02.js
42 lines (38 loc) · 831 Bytes
/
02.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// 02 - Pyramid of Doom / Callback Hell/Soup
//
console.log('Inicio');
step1(function(result1) {
step2(function(result2) {
step3(function(result3) {
step4(function(result4) {
console.log('Result is: '+ result4);
});
});
});
});
console.log('Fin');
function step1(callback) {
setTimeout(function () {
console.log('Hello step 1');
callback(1);
}, (Math.random() * 1000));
}
function step2(callback) {
setTimeout(function () {
console.log('Hello step 2');
callback(2);
}, (Math.random() * 1000));
}
function step3(callback) {
setTimeout(function () {
console.log('Hello step 3');
callback(3);
}, (Math.random() * 1000));
}
function step4(callback) {
setTimeout(function () {
console.log('Hello step 4');
callback(4);
}, (Math.random() * 1000));
}