以$ q.all()的时候调用的一些工作,别人失败会发生什么? [英] What happens with $q.all() when some calls work and others fail?

查看:208
本文介绍了以$ q.all()的时候调用的一些工作,别人失败会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与$ q.all()的时候调用的一些工作,别人失败会发生什么?

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

我有以下的code:

    var entityIdColumn = $scope.entityType.toLowerCase() + 'Id';
    var requests = $scope.grid.data
      .filter(function (rowData, i) {
          return !angular.equals(rowData, $scope.grid.backup[i]);
      })
      .map(function (rowData, i) {
          var entityId = rowData[entityIdColumn];
          return $http.put('/api/' + $scope.entityType + '/' + entityId, rowData);
      });
    $q.all(requests).then(function (allResponses) {
        //if all the requests succeeded, this will be called, and $q.all will get an
        //array of all their responses.
        console.log(allResponses[0].data);
    }, function (error) {
        //This will be called if $q.all finds any of the requests erroring.
        var abc = error;
        var def = 99;
    });

在所有的$ HTTP调用,那么工作allResponses数组填充数据。

When all of the $http calls work then the allResponses array is filled with data.

当其中一个出现故障的这是我的理解,第二个函数将被调用和错误变量给出细节。

When one fails the it's my understanding that the second function will be called and the error variable given details.

但是有人可以帮我解释一下,如果某些响应工作,其他失败会发生什么?

However can someone help explain to me what happens if some of the responses work and others fail?

推荐答案

我相信,因为承诺库基于问:的实现,只要第一个应许被拒绝,拒绝回调被调用的错误。它不会等待其他承诺解决。参见问: https://github.com/kriskowal/q 的文档。对于Q.all这是被提及

I believe since the promise library is based on Q implementation, as soon as the first promise gets rejected, the reject callback is called with the error. It does not wait for other promises to resolved. See documentation of Q https://github.com/kriskowal/q. For Q.all this is what is mentioned

全函数返回值的数组的承诺。当此
  承诺满足,数组包含的履行值
  原来的承诺,以相同的顺序为这些承诺。如果所述一个
  给出的承诺被拒绝,返回的承诺立即
  拒绝,不等待批的其余部分。

The all function returns a promise for an array of values. When this promise is fulfilled, the array contains the fulfillment values of the original promises, in the same order as those promises. If one of the given promises is rejected, the returned promise is immediately rejected, not waiting for the rest of the batch.

这篇关于以$ q.all()的时候调用的一些工作,别人失败会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆