/
aside.js
38 lines (35 loc) · 910 Bytes
/
aside.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
// 'aside' - Promise extension
//
// promise.aside(win, fail)
//
// Works in analogous way as promise function itself (or `then`)
// but instead of adding promise to promise chain it returns context promise and
// lets callback carry on with other processing logic
'use strict';
var callable = require('es5-ext/object/valid-callable')
, deferred = require('../../deferred');
deferred.extend('aside', function (win, fail) {
((win == null) || callable(win));
((fail == null) || callable(fail));
if (win || fail) {
if (!this.pending) {
this.pending = [];
}
this.pending.push('aside', arguments);
}
return this;
}, function (win, fail) {
var cb = this.failed ? fail : win;
if (cb) {
cb(this.value);
}
}, function (win, fail) {
var cb;
((win == null) || callable(win));
((fail == null) || callable(fail));
cb = this.failed ? fail : win;
if (cb) {
cb(this.value);
}
return this;
});