Closed matthewloring closed 7 years ago
I believe this snippet illustrates the underlying problem:
function WrappedPromise(executor) {
var p = new Promise(executor);
p.__proto__ = WrappedPromise.prototype;
return p;
}
WrappedPromise.__proto__ = Promise;
WrappedPromise.prototype.__proto__ = Promise.prototype;
WrappedPromise.prototype.then = function then(onFulfilled, onRejected) {
console.log('WrappedPromiseThen');
return Promise.prototype.then.call(this, onFulfilled, onRejected);
};
class P extends WrappedPromise {
then(onF, onR) {
console.log('PThen');
return Promise.prototype.then.call(this, onF, onR);
}
}
(new P(res => { res(42); })).then(v => { console.log(v); });
Async-listener replaces the global promise with its own function-based class. Other modules extend the global Promise using ES6 class syntax. However, extending the function-based wrapper class does not result in the correct dispatch behavior. I think the best approach may be to rewrite the wrappedPromise
as an ES6 class. Does anyone have thoughts on that change or any other possible approaches?
@watson @Qard @othiym23 Any thoughts on this?
@matthewloring Thanks for the ping 😃 I've commented on the PR
Can we re-opening after revert of the original fix due to https://github.com/othiym23/async-listener/issues/121. I don't have permission.
@watson opened a new issue #123
I could also just reopen this if you guys think that is better?
I think the new issue is good
Test case:
Expected output (and observed when
require('async-listener');
is removed):Observed output:
This issue breaks the got module (by breaking p-cancelable) and can be reproduced with node version 6.x and 8.x.