-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplement ability to subclass Promise #123
Comments
Here's a test case that will break when #113 is applied: global.Promise = require('bluebird')
require('async-listener')
new Promise() Stack trace from Bluebird
|
The correct behavior would be for async listener not to wrap non native promises |
That is actually the intended behavior, that callback is being invoked asynchronously. What this means is either another async should have trigger (a few lines above) or bluebird is using an app not yet wrapped to schedule the async callback. That particular check was to handle bad implementations of promises that resolved a then synchronously |
Oh ignore my previous comment. I think I probably misinterpreted the "should not resolve synchronously" test at first glance. What this test does is checking if |
Sorry for all the typos (I'm on my phone) |
@hayes haha yes you are right - GitHub needs a "is typing...". I just discovered the same thing as evident by my new comment 😄 |
Looks like bluebird uses native promises to schedule it's tasks: https://github.com/petkaantonov/bluebird/blob/master/src/schedule.js which we have not (and now cannot) wrap. This is really inconvenient. |
The only way I see to fix this off the top of my head is to wrap bluebird as if it was native, not a big fan of that though |
Another option - which I'm not a big fan of either - is feature detection. The Bluebird Promise object have a few properties that the native promise doesn't |
The thing I worry about is that promises still need to he wrapped. For an
app using bluebird to work, we do need to wrap something
…On Fri, Jun 23, 2017, 3:36 PM Thomas Watson ***@***.***> wrote:
Another option - which I'm not a big fan of either - is feature detection.
The Bluebird Promise object have a few properties that the native promise
doesn't
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#123 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAx1jymQGauqvr0bh3qPqD1qcoaUPF8Wks5sHD3kgaJpZM4OEFlj>
.
|
We could call into |
In that case, we could.fall back to something other than native promises as the asynchronizer |
I'm not sure this module should patch non-native promise implementations as the patching is complex and can have unexpected consequences (a was the case with bluebird). Also, patching the bluebird scheduler would not give bluebird promises the same behavior as native promises to my knowledge which could make things more confusing as instead of better (there is extra logic to determine what context to propagate when then is called that would be missing among other things). If we want to strengthen the native promise check, maybe we could add: Promise.toString() === 'function Promise() { [native code] }' I'm not aware of a check that would be complete but it seems unlikely that there would be many userspace C++ promise implementations. |
@matthewloring I asked the same question a while back. Seems like some implementations would fake the |
I got a chance to talk to the V8 team a bit about this and there is no way outside of native code to determine definitively that something is a native promise (there is Promise.toString() === 'function Promise() { [native code] }' && Promise.toString.toString() === 'function toString() { [native code] }' |
How does |
Sorry, I missed this before. My github notifications got out of hand so I just did a mark-all-as-read recently. 😥 I'm 👍 on checking |
I’m not sure I understand what you mean by that – if it answers your question, |
async_hooks handled it on the native side, with PromiseHook, since we have async/await to worry about, which bypasses a bunch of the user-facing promise API. Simply patching the then method didn't work there. |
We need to reintroduce the ability to subclass Promise which was allowed by #113 but was reverted in #122. For this to happen we need to make sure we don't break bluebird as evident by #121.
The text was updated successfully, but these errors were encountered: