This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
plugin.none.js
87 lines (73 loc) · 1.73 KB
/
plugin.none.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
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
// "none"
ASQ.extend("none",function $$extend(api,internals){
return function $$none() {
if (internals("seq_error") || internals("seq_aborted") ||
arguments.length === 0
) {
return api;
}
var fns = ARRAY_SLICE.call(arguments);
api.then(function $$then(done){
function reset() {
finished = true;
error_messages.length = 0;
success_messages.length = 0;
}
function complete(trigger) {
if (success_messages.length > 0) {
// any successful segment's message(s) sent
// to main sequence to proceed as **error**
success_messages.length = fns.length;
trigger.fail.apply(ø,success_messages);
}
else {
// send errors as **success** to main sequence
error_messages.length = fns.length;
trigger.apply(ø,error_messages);
}
reset();
}
function success(trigger,idx,args) {
if (!finished) {
completed++;
success_messages[idx] =
args.length > 1 ?
ASQ.messages.apply(ø,args) :
args[0]
;
// all segments complete?
if (completed === fns.length) {
finished = true;
complete(trigger);
}
}
}
function failure(trigger,idx,args) {
if (!finished &&
!(idx in error_messages)
) {
completed++;
error_messages[idx] =
args.length > 1 ?
ASQ.messages.apply(ø,args) :
args[0]
;
}
// all segments complete?
if (!finished &&
completed === fns.length
) {
finished = true;
complete(trigger);
}
}
var completed = 0, error_messages = [], finished = false,
sq = ASQ.apply(ø,ARRAY_SLICE.call(arguments,1)),
success_messages = []
;
wrapGate(sq,fns,success,failure,reset);
sq.pipe(done);
});
return api;
};
});