-
Notifications
You must be signed in to change notification settings - Fork 0
/
seq_tasks.js
37 lines (33 loc) · 865 Bytes
/
seq_tasks.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
/**
* Code based on Node.js in Action by Mike Cantelon, TJ Holowaychuk and Nathan Rajlich
* Chapter 3.4 - Sequencing Asynchronous Logic
*/
var taskList = [
function() {
console.log("func1");
doNextTask(false, "alpha");
},
function(result1) {
console.log("func2, result1: " + result1);
doNextTask(false, "beta");
},
function(result2) {
console.log("func3, result2: " + result2);
doNextTask ("Some serious problem");
},
function(result3) {
console.log("func4, result3: " + result3);
doNextTask (false, "delta");
}
];
function doNextTask(error, result) {
if (error) {
console.log("An error occured: " + error);
} else {
var currTask = taskList.shift();
if (currTask) {
currTask(result);
}
}
}
doNextTask();