-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.html
86 lines (78 loc) · 2.12 KB
/
state.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
<html>
<head>
<title>Test</title>
<!--
async must be included after nodeunit because nodeunit already uses
the async lib internally and will overwrite the version we want to test
-->
<script>
</script>
<script src="state.js"></script>
</head>
<body>
abc....
<script>
var func1 = function(callback){
setTimeout(function(){
console.log(1+"-->");
callback(null, 3);
}, 50);
};
var func2 = function(callback){
setTimeout(function(){
console.log(2+"-->");
callback(null, 5);
}, 100);
};
var func3 = function(callback){
setTimeout(function(){
console.log(3+"-->");
callback(null, 4);
}, 30);
};
var func4 = function(callback){
setTimeout(function(){
console.log(4+"-->");
callback(null, 2);
}, 50);
};
setTimeout(function(){
myQueue.push(func1,function(isSucc,rs){
console.log("1 res back to front!!!"+rs);
})
}, 100);
setTimeout(function(){
myQueue.push(func2,function(isSucc,rs){
console.log("2 res back to front!!!"+rs);
})
}, 200);
setTimeout(function(){
myQueue.push(func3,function(isSucc,rs){
console.log("3 res back to front!!!"+rs);
})
}, 220);
setTimeout(function(){
myQueue.push(func4,function(isSucc,rs){
console.log("4 res back to front!!!"+rs);
})
}, 400);
var myQueue = new Queue();
var total = 7;
myQueue.validFunc=function(rs,cb){
if(rs == null) {//初始化
if(total < 0)
return [false,'订购失败,已卖完'];
else
return [true];
}else{
if(total>=rs){
total = total - rs;
return [true,'订购成功'+rs];
}else{
return [false,'订购失败,超过订购数量!还剩'+total];
}
}
}
</script>
</body>
</html>