$q.all and nested promises

六眼飞鱼酱① 提交于 2019-12-01 17:49:01

Yes it looks like Kevin is correct. I created a quick test in angular as well to confirm the behavior.

angular.module('myModule').controller('testController', function ($q,$scope) {

  function promiseCall(data,timeout) {
    var deferred = $q.defer();

    setTimeout(function() {
      deferred.resolve(data);
      console.log(data);
    }, timeout);

    return deferred.promise;
  }

  var a = promiseCall('call1 a',1000).then(function(){
    return promiseCall('call2 a',50);
  });

  var b = promiseCall('call1 b',500);

  var c = promiseCall('call1 c',1000).then(function(){
    return promiseCall('call2 c',50).then(function(){
      return promiseCall('call3 c',6000);
    });
  });

  $q.all([a,b,c]).then(function(res){
    console.log('all calls are done');
  });

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!