-
Notifications
You must be signed in to change notification settings - Fork 24
/
cb-ctrlsend.js
52 lines (41 loc) · 1006 Bytes
/
cb-ctrlsend.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
47
48
49
50
51
52
/**
* @Author: hooper <hucheng-rj>
* @Date: 2017-Nov-21 1:28:27 pm
* @Email: [email protected], [email protected]
* @Filename: cb-dealsync.js
* @Last modified by: hucheng-rj
* @Last modified time: 2017-Nov-21 2:52:01 pm
*
* @desc cb 处理多异步场景方案1: 控制发出顺序.
*/
function log(data, newLine) {
console.log(JSON.stringify(Object(data)));
newLine && console.log();
}
function ajax(url) {
return function (cb) {
setTimeout(function() {
cb({
url
});
}, Math.random() * 3000);
}
}
const A = ajax('/ofo/a');
const B = ajax('/ofo/b');
const C = ajax('/ofo/c');
log('ajax A send...');
A(function (a) {
log('ajax A receive...');
log(a, true);
log('ajax B send...');
B(function (b) {
log('ajax B receive...');
log(b, true);
log('ajax C send...');
C(function (C) {
log('ajax C receive...');
log(C);
});
})
})