What happens with $q.all() when some calls work and others fail?

后端 未结 7 1593
生来不讨喜
生来不讨喜 2020-11-30 03:09

What happens with $q.all() when some calls work and others fail?

I have the following code:

    var entityIdColumn = $scope.entityType.toLowerCase()          


        
7条回答
  •  执笔经年
    2020-11-30 03:38

    In my case I needed to know when last promise has been resolved no matter if successful or fail. $q.all was not an option because if one fails it goes down immediately. I needed this to make sure user will be redirected no matter what but only if all data are processed (or not) so they can be loaded on next page. So I ended up with this:

    1. Each promise/call implemented also fail callback where "redirect" function is called in both success and fail callbacks.
    2. In this function counter is set, which is increased with each call. If this reaches the number of promises/calls, redirect to next view is made.

    I know it's quite a lame way to do it but it worked for me.

提交回复
热议问题