-
Notifications
You must be signed in to change notification settings - Fork 1
/
09a.js
46 lines (41 loc) · 899 Bytes
/
09a.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
43
44
45
46
//
// 02 - Pyramid of Doom / Callback Hell/Soup
//
var async = require('async');
async.parallel([
function(callback) {
console.log('Inicio');
callback(null, 0);
},
step1,
step2,
step3,
step4
], function(err, results) {
console.log('Result is: ' + results);
console.log('Fin');
});
function step1(callback) {
setTimeout(function () {
console.log('Hello step 1');
callback(null, 'Hola');
}, (Math.random() * 1000));
}
function step2(callback) {
setTimeout(function () {
console.log('Hello step 2');
callback(null, 'Mundo');
}, (Math.random() * 1000));
}
function step3(callback) {
setTimeout(function () {
console.log('Hello step 3');
callback(null, 'Soy Async');
}, (Math.random() * 1000));
}
function step4(callback) {
setTimeout(function () {
console.log('Hello step 4');
callback(null, 4);
}, (Math.random() * 1000));
}