Completablefuture - How to use?

Asked

Viewed 82 times

0

In this situation, how should I work with Completablefuture?

Using the method of Worldcupsocialapi implement the method CompletableFuture<Stream<String>> getMostPopularTeamNames(int maxResults), where maxResults indicates the maximum number of results to be obtained. For example, to get the names of the 5 most popular selections, the method must be invoked with maxResults = 5.

class WorldCupSocialApi { 
// Invoca o callback teamsConsumer com a lista de nomes das seleções mais 
// populares, com as posições de popularidade from e to. 
// Exº para obter as 5 seleções mais populares, este método deve ser invocado 
// com from = 1 e to = 5. Caso não existam seleções nesse intervalo, é 
// invocado com uma lista vazia.


public static void getMostPopularTeamNames(int from, int to, Consumer<List<String>> teamsConsumer); 
}

1 answer

0


CompletableFuture<Stream<String>> getMostPopularTeamNames(int maxResults){
    CompletableFuture<Stream<String>> mostPopularTeamNames;
    WorldCupSocialApi.getMostPopularTeamNames(1, maxResults, (teams) -> {
        mostPopularTeamNames = CompletableFuture.supplyAsync(() -> teams.stream());
    });
    return mostPopularTeamNames;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.