Fix ThenanbleRef promise
This commit is contained in:
parent
7f99b035e2
commit
d23c048304
|
@ -481,30 +481,38 @@ export default class Reference extends ReferenceBase {
|
||||||
* Access then method of promise if set
|
* Access then method of promise if set
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
get then() {
|
then(fnResolve, fnReject) {
|
||||||
if (this._promise && this._promise.then) {
|
if (isFunction(fnResolve) && this._promise && this._promise.then) {
|
||||||
return this._promise.then.bind(this._promise)(() => {
|
return this._promise.then.bind(this._promise)((result) => {
|
||||||
this._promise = null;
|
this._promise = null;
|
||||||
return this;
|
return fnResolve(result);
|
||||||
|
}, (possibleErr) => {
|
||||||
|
this._promise = null;
|
||||||
|
|
||||||
|
if (isFunction(fnReject)) {
|
||||||
|
return fnReject(possibleErr);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw possibleErr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return throw new Error("Cannot read property 'then' of undefined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access catch method of promise if set
|
* Access catch method of promise if set
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
get catch() {
|
catch(fnReject) {
|
||||||
if (this._promise && this._promise.catch) {
|
if (isFunction(fnReject) && this._promise && this._promise.catch) {
|
||||||
return this._promise.catch.bind(this._promise)((exception) => {
|
return this._promise.catch.bind(this._promise)((possibleErr) => {
|
||||||
this._promise = null;
|
this._promise = null;
|
||||||
return Promise.reject(exception);
|
return fnReject(possibleErr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return throw new Error("Cannot read property 'catch' of undefined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue