userit1985 :
My method gets Flux. How do I iterate over Flux? I would like to go over its objects and do operation on every Child.
public void write(List<? extends Flux<Child>> childFlux) throws Exception {
childFlux.stream()
.map(children -> children.collectList())
.forEach(child -> run(child); //not compile
}
public void run(Child child) {
//TO DO
}
JEY :
This seems like an anti-pattern. However there are some basic mistakes.
map(children -> children.collectList())
will return aMono<List<Child>>
forEach(child -> run(child);
you forgot one closing bracket and should beforEach(child -> run(child));
.- But it won't compile because child will be a
Mono<List<Child>>
and not aChild
- When you are using reactive programing nothing happend before subscribe
What you realy need to do is something like
Flux.concat(childFlux).subscribe(this::run)
Concatenate all sources provided in an Iterable, forwarding elements emitted by the sources downstream.
Or
Flux.merge(childFlux).subscribe(this::run)
Merge data from Publisher sequences contained in an array / vararg into an interleaved merged sequence. Unlike concat, sources are subscribed to eagerly.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325075&siteId=1