Skip to content

Commit

Permalink
Fixed a potential bug with late internal event listeners appending;
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed Apr 13, 2021
1 parent de76880 commit 6e3e0b2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/c-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,6 @@ class CPromise extends Promise {
this.onResume = this.onResume.bind(this);
this.onCapture = this.onCapture.bind(this);

if (executor != null) {
if (typeof executor !== 'function') {
throw TypeError('CPromise executor is not a function');
}

try {
executor.call(this, value => {
this.resolve(value)
}, err => {
this.reject(err)
}, this);
} catch (err) {
this.reject(err);
}
}

signal !== undefined && this.listen(signal);

timeout !== undefined && this.timeout(timeout);
Expand Down Expand Up @@ -213,6 +197,22 @@ class CPromise extends Promise {
}
}
})

if (executor != null) {
if (typeof executor !== 'function') {
throw TypeError('CPromise executor is not a function');
}

try {
executor.call(this, value => {
this.resolve(value)
}, err => {
this.reject(err)
}, this);
} catch (err) {
this.reject(err);
}
}
}

/**
Expand Down

0 comments on commit 6e3e0b2

Please sign in to comment.