需要帮助解决嵌套的promises,Promise没有得到解决

时间:2016-09-28 09:35:54

标签: javascript angularjs angular-promise

我有一个服务设计,它接受一些参数,然后循环通过输入数组,找出哪个项是空的,然后将它们添加到和数组然后在$ q.all解决后它应该给我空数组的数组

输入是项目数组

function getElements(inputs) {
            var elements= [],
                promise, whenPromise,
                promises = [],
                mainPromise = $q.defer();
            if (inputs.length === 0) {
                mainPromise.resolve(elements);
                return mainPromise.promise;
            }

            angular.forEach(inputs, function (input) {
                promise = getPromises(input);
                whenPromise = $q.resolve(promise).then(function (response) {
                $timeout(function() {
                        if (response.isEmpty) {
                  **//perform action with the response.data;**
                        }
                  });
                }, function () {

                });

                promises.push(whenPromise);
            });


            $q.all(promises).finally(function () {
                 mainPromise.resolve(outdatedEntities);

            });

            return mainPromise.promise;
        }

        function getPromises(input) {
            var deferred = $q.defer();

            someSerivce.getItemDetails(input.Id).then(function (value) {
                if (value === null) {
                    $timeout(function () {
                        deferred.resolve({data: input, isEmpty: true});
                    });

                } else {
                    //have item locally, but need to see if it's current
                    input.isEmpty().then(function (isEmpty) {
                        $timeout(function () {
                            deferred.resolve({data: input, isEmpty: isEmpty});
                        });
                    }, function (error) {
                        deferred.reject(error);
                    });
                }

            });

            return deferred.promise;
        }

现在,问题是$ q.all永远不会解决。尽管所有内部承诺都得到了解决。

1 个答案:

答案 0 :(得分:1)

这应该有效:

Config config = new Config();
config.useSentinelServers()
   .setMasterName("mymaster")
   .addSentinelAddress("127.0.0.1:26389", "127.0.0.1:26379")

RedissonClient redisson = Redisson.create(config);

RMap<MyKey, MyValue> map = redisson.getMap("myMap");
map.put(new MyKey(), new MyValue());