Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

WIP STAGING for #8300 [[no-merge]] #8067

Closed
wants to merge 8 commits into from
Closed

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Jul 3, 2014

Staging ground for $q improvements in #8300, this is a work in progress.

The work is in 3 stages, each building on the previous stage:

  1. Add constructor for promises (ES6-style interface, landed in f3a763f)
  2. Port subset of functionality from Bluebird, we can now get a perf improvement by sticking methods used for each promise in the prototype chain and avoid creating garbage.
  3. Modify the error logging behaviour to be similar to Bluebird, by only logging an error for unhandlde rejections.

This is somewhat challenging, as promises in $q currently behave somewhat inconsistently (sometimes rethrowing errors, sometimes not, etc), and it will take some time to finalize this. Hence, staging ground.

@@ -8,6 +8,37 @@
* @description
* A promise/deferred implementation inspired by [Kris Kowal's Q](https://github.com/kriskowal/q).
*
* $q can be used in two fashions --- One, which is more similar to Kris Kowal's Q or jQuery's Deferred
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's an alternative way to use the API and it doesn't support all methods, it's documentation should come after $q, simply to prevent confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, it should come first IMO. Supporting "all the methods" would just mean adding an extra parameter to the resolver function.

Since this is basically what Promise APIs look like these days, it's actually saner to put this up front, with the older style further down --- and the older style should probably be eventually deprecated

describe('$Q', function() {
var resolve, reject, resolve2, reject2;
/* jshint newcap:false */
var Q = function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling this helper function Q is a bit misleading. how about just createPromise or something that tells the test reader that the function call is a test helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@Narretz Narretz added this to the Backlog milestone Jul 17, 2014
@jeffbcross jeffbcross modified the milestones: 1.3.0-beta.17, Backlog Jul 21, 2014
@jeffbcross jeffbcross self-assigned this Jul 21, 2014


$$proxyPromise: function Promise$$proxyPromise(promise) {
if (this.isResolved()) throw new Error('Cannot proxy for resolved promise');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions were just used for debugging, it would be helpful to keep them but they probably won't look like this.

The promise-proxying strategy of Bluebird is a keeper, I think. Promise$$cast and $$proxyPromise have been helpful.

@caitp
Copy link
Contributor Author

caitp commented Jul 22, 2014

so the current state of things is, aplus tests are passing (I think these are still old versions of the aplus tests though), however many angular tests are failing due to issues with the promises. Some of those have been sorted out (deferred objects and promises must now be called with their correct context, so $http had to change slightly), but I'm still sorting through the broken ones to see what needs to be done.

@jeffbcross
Copy link
Contributor

I don't see any benefit in making all of these $q changes in one PR. There is one commit that's nearly ready to go, but is blocked by being merged because of a big experimental refactor.

@caitp can we separate this into multiple PRs, and create a detailed issue enumerating the improvements we intend to make with the refactor?

  • First PR for added ES6-like features and A+ compliance (mostly done within the first commit)
  • Second PR for performance improvements, focused on improving gc/memory pressure

@caitp caitp changed the title feat($q): add streamlined ES6-style interface for using $q WIP STAGING for #8300 [[no-merge]] Jul 23, 2014
@caitp
Copy link
Contributor Author

caitp commented Jul 25, 2014

@juliemr I think this is currently breaking something in how protractor interacts with the app, because as far as I can tell the tests which are failing are working as expected.

Can you think of anything which would causes issues there?

@juliemr
Copy link
Member

juliemr commented Jul 25, 2014

@caitp I don't see an obvious cause. I can take a longer look tomorrow, but it's odd that it's only that one test which is failing. We should figure out if it's a synchronization issue by putting in a browser.sleep(2000) after the click (https://github.com/angular/angular.js/blob/master/src/ngRoute/route.js#L357). If it passes then, it's a sync issue.

@juliemr
Copy link
Member

juliemr commented Jul 25, 2014

As far as I can tell this is a real bug. Go to http://localhost:8000/build/docs/examples/example-$route-service/ and try clicking the different links - the text in the view doesn't always update.

Note that the bindings below the view update, but the view itself doesn't.

@caitp
Copy link
Contributor Author

caitp commented Jul 25, 2014

When I was testing, I would always see the animation run and the UI update as expected. hm...

@caitp
Copy link
Contributor Author

caitp commented Jul 25, 2014

Thanks for looking into it, I'll try and figure that out I guess

@jeffbcross
Copy link
Contributor

CC @petkaantonov: @caitp is experimenting with swapping out some of (all of?) the $q implementation to improve performance and debuggability. Any insight you have on her approach would be great.

And thanks for the comments and emails @benjamingr!

caitp added 8 commits July 31, 2014 08:34
Things remaining:

1. Make this compatible with the original $q implementation

2. Sort out the error logging story (make use of Bluebird's machinery for this + $exceptionHandler by default)

3. Remove more bits that aren't needed for Angular.
@caitp
Copy link
Contributor Author

caitp commented Jul 31, 2014

So, as I mentioned in the dev-chat, the problem which was breaking this previously was that some ngRoute e2e tests were failing due to depending on unbounded execution of Deferred.resolve() --- I've added support for this back in to fix those tests, and I think that should fix all of the breaking changes that would be introduced by this patch (I've re-enabled tests which were previously disabled earlier in the prototype due to breaking exactly that aspect).

So I think this is good for a more proper review so we can look at the parts we want to get rid of and the parts we want to hang onto.

@caitp
Copy link
Contributor Author

caitp commented Jul 31, 2014

Welp, Igor didn't like this one, so closing it in favour of #8437, will sort out the remaining issues later

@caitp caitp closed this Jul 31, 2014
@caitp caitp removed this from the 1.3.0-beta.18 milestone Jul 31, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants