-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
53 lines (43 loc) · 798 Bytes
/
example.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
53
var $ = require('jquery-deferred'),
ChainLoading = require("./ChainLoading.js");
var chain = new ChainLoading(),
d1 = new $.Deferred(),
d2 = new $.Deferred(),
d3 = new $.Deferred();
//level 1
chain.done(function() {
console.log(0);
});
// level 2
chain.push(d1).done(function(c) {
console.log(c);
}).fail(function() {
console.log("1 failed");
});
//level 3
chain.push(d2).done(function(c) {
console.log(c);
}).fail(function() {
console.log("2 failed");
});
chain.done(function(c) {
console.log(c);
}, true);
//level 4
chain.push(d3).done(function(c) {
console.log(c);
}).fail(function() {
console.log("4 failed");
});
d3.resolve(4);
d2.resolve(2);
d1.resolve(1);
/**
Will produce:
0
1
2
2
3
no matter what order the deferreds resolve in
**/