0

我目前正在使用带有并行任务的螺栓框架(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();
    }
4

0 回答 0