Looking for converting Flux to List<Object>. Getting error if I use block(). So, need to conver without blocking calls.
Flux.from(Collection.find())
Using reactive programming, but graphql expects List<objects> and erroring with returning Flux.
Code with Block()
public List<Test> findAll() {
return Flux.from(testCollection.find()).collectList().block();
}
Error :-
block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-kqueue-7
Here, I need to return List<Test> as I can not send Flux<Test> for some reason.
As stated in the comments, You can't. The reactive pattern is to stay in a flow.
So,
Mono<GraphqlResponse> = Flux.just("A", "B" "C")
.collectList()
.map(this::someMethod);
GraphqlResponse someMethod(List<String> abcs) {
return graphQl.doSomething(abcs);
}
following example is converting flux<Object> to List<Object> but remember that converting a Flux to a List makes the whole thing NOT reactive:
public static void main(String[] args) {
Flux<String> flux = Flux.just("test1", "test2", "test3");
List<String> list = new ArrayList<>();
flux.collectList().subscribe(list::addAll);
list.forEach(System.out::println);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With