-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Q resolve outside of $digest #2881
Comments
If you use a Q implementation which lives outside of angular world, wrap the calls in |
This is really annoying... I also worked on an app with a lot of chained digest events. Q implementation should definitely live inside the angular world or should be integrated! It's weird that execution sometime stops and proceeds when an UI interaction happens. At least on some mobile devices. |
@PascalPrecht starting a $digest every time I use a promise is not an option for me. There are performance considerations. |
@andi1984 Uhm... there is a Q implementation inside of angular ? Just use |
@PascalPrecht No, I'm already used the $q service, but it seems that some mobile devices have problems with chained callbacks, at least via the $q service. The execution stops at some deeper level and proceeds when a new UI interaction was done. |
@andi1984 it's like that so you can use promises in your model data & templates and have it work as expected. |
I've a jsFiddle which indicates the complexity of using $q http://jsfiddle.net/Lpadg/ I think the problem is nextTick in angular. Which could/should schedule the tick handler. // in nextTick
if (!tickScheduled) {
tickScheduled = true;
setTimeout(function () {
tickScheduled = false;
handleTick();
}, 0);
} |
Encountering this as well (see #2993), exposing |
It seems silly to have promises only become resolved once a $digest() happens imo. Consider the following:
Nothing in there explicitly should require a $digest() to occur, so requiring that code to be wrapped in a $timeout seems silly, however that request will actually never happen until a $digest() occurs since internally What's the actual benefit of tying a promise's resolution to the $digest() cycle in the first place? |
That's the main question. I also didn't and still don't get it. But related to isssue #2894, it seems that you have to wrap it by a manual
But, as you, I don't see any deeper sense in that... |
@andi1984 in fact you can't rely on
I think it was a way to minimize rendering iterations as promises are somehow queued to the $digest cycle and are all resolved at the same time (at the beginning of the next digest). It is a clever design choice, but we need to be able to use actual |
@mgcrea something like icholy@81bd59c example The problem is
Or there could just be another EDIT If backward compatibility wasn't an issue you could rename |
Same issue here, it's really annoying. |
@icholy have you submitted a PR with your patch? My use-cases are not bound to Any chance to get this into |
Is the problem that the overhead associated with using a $timeout to invoke $digest is too expensive? I noticed this problem and just wrapped all my resolves in a $timeout, should probably do the same for reject. E.g.
|
I'm an angular neophyte. This 'issue' seems to be affecting me, now that I have upgraded my angular library. I'm using ngResource. If I understand this thread correctly, when I do
it just works. But if I do
then I have to do something additional? Uh - I have to wrap the callback in a timeout?
That's correct, and (not to put too fine a point on it) on purpose? Ah, no - it turns out that I need to do:
Or at least that seems to work at this moment in time. |
this has been resolved in 1.2.0rc2 by 6b91aa0 closing... |
Sorry, but even in 1.2.0-rc.3 using $q is impractical compared to the real Q. http://jsfiddle.net/bfanger/Lpadg/ |
Till we upgrade the angular version, in our app we plan to go with the following monkey patch in app.config as a work-around:
|
http://www.slideshare.net/domenicdenicola/the-promised-land-in-angular @Vibhor86 Your decorator workaround to makes the resolve() synchronous creating subtle bugs, and is neglecting the reject and notify. |
@bfanger your fiddle is incorrect because it assumes that angular will use setTimeout for task scheduling to make promises async. the fact is that it uses $timeout, which gets automatically mocked-out when you load angular-mocks.js. This allows you to write the beautiful synchronous tests without compromising any promise guarantees. Check out this fork of your fiddle: http://jsfiddle.net/ZKcp6/ unfortunately if you mix Q and $q promises (which you can by doing In any case, the Angular-specfic slides in the slide deck you are referring to are outdated or plain wrong. Unfortunately Domenic misunderstood the reasoning behind some of the $q design decisions and didn't check with us before publishing the slides. |
After further testing, the fix in 1.2.0rc2 indeed works a advertised. Thanks for explaining the connection with $timeout, which causes the unexpected $q resolve behavior when using ngMock. |
Sure. I'm glad that it works for you :-)
|
I have a lot of code in services that use Q promises for async stuff. I can't use $q because it only resolves in a $digest cycle. I really don't want to include 2 copies of the Q library but, by the looks of it, I have to.
I don't know if this has been discussed, but could there be another method added to deferreds? Something like
deferred.resolveNow(/* stuff */)
which doesn't usenextTick
The text was updated successfully, but these errors were encountered: