这是我想要获取结果并始终将monoUserContent设为空的所需代码
public Mono<UserResponse> functionABC(){
Mono<List<User>> monoUserType = service.getType(); //calling service
Mono<List<Content>> monoUserContent = service.getUserContent(userType);
Mono<UserResponse> response = null;
Mono<Tuple2<List<User>, List<Content>> zipped = Mono.zip(monoUserType, monoUserContent);
response = zipped.flatMap( t -> {
List<User> tupleUserType = tuple.getT1();
List<Content> tupleUserContent = tuple.getT2();
Mono<UserResponse> userRes = userCombinator.bindData(tupleUserType, tupleUserContent );
return userRes;
});
return response;
}
在运行以下代码段时,
public Mono<UserResponse> functionABC(){
Mono<List<User>> monoUserType = service.getType(); //calling service
Mono<List<Content>> monoUserContent = service.getUserContent(userType);
try {
thread.sleep(3000);
} catch(Exception e) {
e.printStackTrace();
}
Mono<UserResponse> response = null;
Mono<Tuple2<List<User>, List<Content>> zipped = Mono.zip(monoUserType, monoUserContent);
response = zipped.flatMap( t -> {
List<User> tupleUserType = tuple.getT1();
List<Content> tupleUserContent = tuple.getT2();
Mono<UserResponse> userRes = userCombinator.bindData(tupleUserType, tupleUserContent );
return userRes;
});
return response ;
}
它为我工作。添加thread.sleep(5000),神奇了。
我知道这不是正确的方法,我该如何处理这种情况?