-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Core & multiple modules: refactor usage of Promise to avoid deferrals when possible #8626
Conversation
adcdd81
to
ae97a21
Compare
@dgirardi is it simple to prepare a backport of this to legacy? |
@patmmccann it shouldn't be too hard, but I'll wait for a review on this before attempting it. |
6bfc7c0
to
9d19244
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell/understand, I think this all looks okay.
As a possible thought, given the shift this PR is introducing to prebid.js' internal Promise model to force a synchronous execution - is there any value to setting up a separate standard interface/model that uses the normal Promise behavior?
I saw with some of files that the functions use a base Promise
to help with the their execution (or debugging). Should those base Promise use-cases be something that we want to build a control mechanism within Prebid.js - to future-proof any potential future changes (like this)? Or is that not really needed/not a big deal if it were to happen.
@jsnellbaker I'm not sure I understand your question. Do you mean something like marking "normal" promises as a lint error? I'm not against it, but also not convinced it's going to be that useful (because in some situations normal promises are the correct choice, so ultimately the contributor needs to know the difference). |
this looks fine to me and yeah, as you say, regular good work on the Promise test suite, really gives me confidence that the replacement functions as expected! |
I was thinking of how we have an internal interface for ajax calls that we ask everyone to use (to control how the calls are executed/maintained/etc) instead of everyone creating their own references; so my previous thought would be mimicking that setup/usage behavior in Prebid.js to setup something for 'normal' Promises, for everyone to use in a standardized way. But as I said, it was just a potential thought. |
@jsnellbaker a wrapper around Promise would have no substance, I think, so at the moment I don't see the utility. (ajax would historically provide an interface for xmlhttprequest, and has some prebid-specific logic for timeouts and so on, Promise would just be Promise, renamed). |
… when possible (#8626) * Core & multiple modules: refactor usage of Promise to avoid deferrals when possible * Unhandled rejection handling * Improve tests
… when possible (prebid#8626) * Core & multiple modules: refactor usage of Promise to avoid deferrals when possible * Unhandled rejection handling * Improve tests
It seems as if this change is incompatible with bluebirdjs. When using Prebid.js 7.7.x+ we get the following error on one our publisher's sites: Uncaught TypeError: the promise constructor cannot be invoked directly and the auction doesn't proceed. We believe it's due to GreedyPromise extending Promise: http://bluebirdjs.com/docs/error-explanations.html#2.-you-are-trying-to-subclass-promise Unfortunately we can't simply ask the publisher to remove bluebirdjs so it would be awesome if it was possible to find a way around this. It doesn't seem like something easy to do, but the publisher is a major one and I would assume this could happen elsewhere as well. |
Bluebird is not recommended on older browsers. Your publisher should not be loading modern prebid and bluebird together, they should load old prebid and bluebird for old browsers, no bluebird and modern prebid for modern browsers. |
… when possible (prebid#8626) * Core & multiple modules: refactor usage of Promise to avoid deferrals when possible * Unhandled rejection handling * Improve tests
Type of change
Description of change
This refacts all usage of Promise in the "critical" path (from requestBids to renderAd) to run synchronously if possible, in light of this discussion.
The approach is swapping
Promise
with a customGreedyPromise
that will avoid giving up control if it can. Apart for the difference in callback execution timing, the two should be interchangeable.