简体   繁体   中英

Spring Webflux Wait for a Flux inside a Flux

Here is the scenario, i Have a Flux that comes from a ReactiveMongoDB and another from WebClient, soo i need that for each item in Mongodb, I look for his items in a webclient.

The problem is that, i have been using block to wait from the webclient itens to come and this is affecting the performance.

If i not use Block, the response is send without the itens from webClient, soo its probaly not waiting this itens do come.

Is there any way to make all calls and wait later from this itens?

 return planetaRepository.findAll().flatMap(planetaVO -> {
                planetaServiceFacade.recuperarFilmesParticipados(planetaVO.getNome()).collectList().doOnNext(planetaVO::setFilmes).block();
                return Flux.just(planetaVO);
            });

You can try something like this instead, by using thenReturn

return planetaRepository.findAll().flatMap(planetaVO -> {
    return planetaServiceFacade.recuperarFilmesParticipados(planetaVO.getNome()).collectList()
                        .doOnNext(planetaVO::setFilmes)
                        .thenReturn(planetaVO);
});

And i suggest you dont write code in your native language, if you are not forced to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM