-
Notifications
You must be signed in to change notification settings - Fork 0
/
qTest.html
98 lines (87 loc) · 2.29 KB
/
qTest.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<html>
<head>
<script src="ext/q.js"></script>
<script>
function step0() {
Q.delay(3100).done(function() {
console.log('step0 delayed');
});
}
// even though step1 takes longer than step2, step1 results diplay before step2 results
function step1(successIndicator) {
var deferred = Q.defer();
setTimeout(function() {
console.log('step1 async');
deferred.resolve(successIndicator);
}, 2000);
return deferred.promise;
}
function step2(successIndicator) {
var deferred = Q.defer();
setTimeout(function() {
console.log('step2 async');
deferred.resolve(successIndicator);
}, 1000);
return deferred.promise;
}
function step3() {
var deferred = Q.defer();
try {
badconsole.log('step3 async');
}
catch(ex) {
deferred.reject(new Error(ex));
}
deferred.resolve(3);
return deferred.promise;
}
function step2WaitsButInputDoesNotDependOnStep1_Output() {
step1(1).then( function(step1SuccessResult) {
console.log('step1 result: ' + step1SuccessResult);
}).then( function() {
step2(2).then( function(step2SuccessResult) {
console.log('step2 result: ' + step2SuccessResult);
});
}).done();
}
function step2WaitsButInputDoesNotDependOnStep1_Output_NoLogging() {
step1(1).then(function() {
step2(2).then(function() {
step3()
})}).done();
}
function step2WaitsAndInputDependsOnStep1_Output() {
return step1(1).then( function(step1SuccessResult) {
console.log('step1 result: ' + step1SuccessResult);
return step2(step1SuccessResult).then( function(step2SuccessResult) {
console.log('step2 result: ' + step2SuccessResult);
})
}).done();
}
function main() {
console.log('do this right away');
//step0();
//step2WaitsButInputDoesNotDependOnStep1_Output();
//step2WaitsButInputDoesNotDependOnStep1_Output_NoLogging();
//step2WaitsAndInputDependsOnStep1_Output();
/*
step1(1).then(function(success) {
console.log('step1 result: ' + success);
step2(2).then(function(success) {
console.log('step2 result: ' + success);
})
}).done();
*/
step3(3).then(
function (success) {
},
function(error) {
console.error(error);
}).done();
console.log('do this whenever');
}
</script>
</head>
<body onLoad="main();">
</body>
</html>