Skip to content

Commit

Permalink
Improved toString() logic;
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed Apr 20, 2021
1 parent d004aa1 commit 7876164
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/c-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ const ATOMIC_TYPE_DISABLED = 0;
const ATOMIC_TYPE_DETACHED = 1;
const ATOMIC_TYPE_AWAIT = 2;

const atomicMap2= {
'disabled': ATOMIC_TYPE_DISABLED,
'detached': ATOMIC_TYPE_DETACHED,
'await': ATOMIC_TYPE_AWAIT,
}
const noop = () => {
};

const atomicMap= new Map([
['disabled', ATOMIC_TYPE_DISABLED],
Expand Down Expand Up @@ -687,8 +684,7 @@ class CPromise extends Promise {
shadow.isRejected= isRejected;
shadow.value = value;
if (isRejected) {
shadow.isCanceled && !shadow.leafsCount && super.then(null, () => {
});
shadow.isCanceled && !shadow.leafsCount && super.then(null, noop);
this.emit('done', value, isRejected);
shadow.reject(value);
} else {
Expand Down Expand Up @@ -1743,10 +1739,7 @@ class CPromise extends Promise {
});
});

return promise.then((value) => {
setProgress(1, promise);
onFulfilled(value)
}, onRejected);
return promise.then(onFulfilled, onRejected);
}

onFulfilled();
Expand Down Expand Up @@ -1926,11 +1919,13 @@ class CPromise extends Promise {
return super.toString();
}

const renderStatus= (scope)=>{
if(scope.isPaused) return 'paused';
if(scope.isPending) return 'pending';
const value= scope[_shadow].value;
return `${scope.isRejected? 'rejected' : 'resolved'}${value===undefined? '' : `<${value}>`}`;
const renderStatus = (scope) => {
if (scope.isPaused) return 'paused';
if (scope.isPending) return 'pending' +
(scope[_shadow].computedProgress !== -1 ?
`[${(scope[_shadow].computedProgress * 100).toFixed(1)}%]` : '');
const value = scope[_shadow].value;
return `${scope.isRejected ? 'rejected' : 'resolved'}${value === undefined ? '' : `<${value}>`}`;
}

return this.scopes()
Expand Down

0 comments on commit 7876164

Please sign in to comment.