| 1 |
// 'aside' - Promise extension |
| 2 |
// |
| 3 |
// promise.aside(win, fail) |
| 4 |
// |
| 5 |
// Works in analogous way as promise function itself (or `then`) |
| 6 |
// but instead of adding promise to promise chain it returns context promise and |
| 7 |
// lets callback carry on with other processing logic |
| 8 |
|
| 9 |
"use strict"; |
| 10 |
|
| 11 |
var isValue = require("es5-ext/object/is-value") |
| 12 |
, callable = require("es5-ext/object/valid-callable") |
| 13 |
, deferred = require("../../deferred"); |
| 14 |
|
| 15 |
deferred.extend( |
| 16 |
"aside", |
| 17 |
function (win, fail) { |
| 18 |
if (isValue(win)) callable(win); |
| 19 |
if (isValue(fail)) callable(fail); |
| 20 |
if (win || fail) { |
| 21 |
if (!this.pending) { |
| 22 |
this.pending = []; |
| 23 |
} |
| 24 |
this.pending.push("aside", arguments); |
| 25 |
} |
| 26 |
return this; |
| 27 |
}, |
| 28 |
function (win, fail) { |
| 29 |
var cb = this.failed ? fail : win; |
| 30 |
if (cb) { |
| 31 |
cb(this.value); |
| 32 |
} |
| 33 |
}, |
| 34 |
function (win, fail) { |
| 35 |
var cb; |
| 36 |
if (isValue(win)) callable(win); |
| 37 |
if (isValue(fail)) callable(fail); |
| 38 |
cb = this.failed ? fail : win; |
| 39 |
if (cb) { |
| 40 |
cb(this.value); |
| 41 |
} |
| 42 |
return this; |
| 43 |
} |
| 44 |
); |