对于for / forEach循环,不会遍历所有项目

时间:2018-02-23 21:51:47

标签: java loops lambda bolts-framework

我目前正在使用具有并行任务的bolt框架(Task.whenAll()),我将所有任务添加到列表中。首先,我需要遍历我的名单,但它只是在第一次迭代后停止迭代(在循环[1]中)。 任务执行,但仅适用于循环中的第一项。之后它就会停止。所以它只进行了一次迭代。

这是arrayList lHoster的一个例子:[Vivo,OpenLoad,Streamango,FlashX,OpenLoadHD,TheVideo]

public Task<HashMap<String, Object>> getEpisode(String series, int season, String episode) {
        TaskCompletionSource<HashMap<String, Object>> completion = new TaskCompletionSource<>();
        getEpisodeInformation(series, season, episode).onSuccess(task -> {
            List<String> lHoster = (ArrayList<String>) task.getResult().get("hoster");
            List<Task<?>> tHoster = new ArrayList<>();
            // Loop [1]. It only iterates through the first item, then just continues without any reason. Although there are normally 8 items in the string list
            lHoster.forEach(host -> tHoster.add(getOutLink(series, season, episode, host)));
            Task.whenAll(tHoster).onSuccess(task1 -> {
                List<HashMap<String, String>> hoster = new ArrayList<>();
                int i = 0;
                for (Task t : tHoster) {
                    HashMap<String, String> hostData = new HashMap<>();
                    hostData.put("out", (String) t.getResult());
                    hostData.put("name", ((ArrayList<String>) task.getResult().get("hoster")).get(i));
                    i++;
                }
                task.getResult().put("hoster", hoster);
                completion.setResult(task.getResult());
                return null;
            });
            return null;
        });
        return completion.getTask();
    }

0 个答案:

没有答案