For for/forEach loop doesn't iterate over all items

549 views Asked by At

I'm currently using the bolts framework with parallel tasks (Task.whenAll()), I'm adding all my tasks into a list. Firstly I need to loop through my names list, but it just stops iterating after the first iteration (in the loop [1]). The tasks get executed, but only for the first item in the loop. After that it just stops. So it makes only one iteration.

This is an example for the 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

There are 0 answers