简体   繁体   中英

How i can return a response if it depends of a Mono object?

I am new with reactive programing and i need help to understeand this scenario.

@autowired
private e;

private Mono<b> method1(list<a> object1){
   
  b object2 = new b();
  c object3 = new c();
  f object5 = new f();

  for (a obj : object1) {
       Mono<d> object4 = e.getD(obj.getSomething(), obj.getSomething2());
      //I need stop this mapping when a condition is Meet and continue the logic downstream 
       object4.map(mapper->{
            int status= mapper.getStatus();
            if(status == 200){
                object2.setSomethingElse(mapper.getValue1());
                object3.setSomethingElse(mapper.getValue2());
               //do something and stop execution
                object5.setSomethingElse2(mapper.getValue3());
            }
            //if that condition is not meet then continue
            //more logic doing other set to other values of object2 and 3
       });

  }
  object3.setF(object5);
  object2.setB(object3);
  return Mono.just(object2);
}

the problem is that when i map into the loop i need to return a response but i dont want do it in that moment i want that the loop ends mapping all values of the dependencies objects and then continue the execution of the method. i hope someone understeand me. I repeat i am new with reactive programing so i dont know if i doing something wrong.

Mono.block() will return the response after the computation is done.

Below code should work.

return Mono.just(object2).block();

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