1
다른 반환 유형을 가진 스트림 \ Observables간에 작성하는 방법을 이해하는 데는 개념적으로 문제가 있습니다. 1. 방법을 .ZIP 사용하여 관찰 가능한 2 방출 :streams Observables를 올바르게 작성하는 방법
public void findSeat() {
rx.Observable<GameObject> userObs = context.getUser();
rx.Observable<ActiveGame> gameObs = context.findGame();
rx.Observable.zip(userObs, gameObs, (userObj, game) -> {
User user = ...;
final List<Object> results = new ArrayList<Object>(3);
if(userObj.getStatus() != ErrorCodes.STATUS_OK) {
results.add(-1);
return results;
}
...
...
//***********************************
// THE PROBLEM IS HERE:
// "context.getActiveGameManager().updateGame(game)" returns Observable<GameOBject> and not List<Object> like .zip() expects.
// because of that I cannot do:
// "return context.getActiveGameManager().updateGame(game);"
// How can I do this convertion from Observable<GameObject> to List<Object>
//************************************
context.getActiveGameManager().updateGame(game)
.map((gameObj) -> {
if(gameObj.getStatus() != ErrorCodes.STATUS_OK) {
results.add(-2);
return (Observable<? extends Object>) results;
}
results.add(ErrorCodes.STATUS_OK);
results.add(user);
results.add(gameObj);
return gameObs;
});
return Observable.empty();
}).subscribe((results) -> {
int status = (int) results.get(0);
User user = (User) results.get(1);
ActiveGame game = (ActiveGame) results.get(2);
replyObj.reply(new JsonObject()
.putString("action", CommandActions.FIND_SEAT)
.putNumber("status", status);
.putNumber("game_id", game.getGameId())
);
});
}
흐름은 다음과 같다 : 여기
내가 코드를 시도하고 초안 방법이다. 2. 스트림의 반환 값에 대해 일부 논리를 수행하고 결과가 error-code -> 목록에 넣고 반환하면 "subscribe"가 오류를 사용자에게 반환 할 수 있습니다. 3. 오류가 없으면 flatMap()을 사용하여 다른 "업데이트"메서드를 내 보냅니다. 여기에 문제가 있습니다. 4. 결국 모든 결과는 "구독"으로 처리되어야합니다. 사용자가 그의 요청에 대해 인정하는 지점이기 때문입니다.는 그런데
, 나는 rxJava를 배우려고 노력하고있어 ... 충분히 분명 희망하지만 내가 충분히 \ 좋은 소스가 찾을 매우 어렵습니다 - 사람이 배울 수있는 가장 좋은 방법 나에게 추천 할 수 있습니다 그것?? 나는 Youtube, Wikipedia, Github에서 튜토리얼을보고있다. 그들 대부분은 스칼라와 다른 스크립팅 언어를 가르치고있다. 자바에서는 아무것도 찾을 수 없다.노력 해 주신 여러분 감사합니다 !!
WOW - 답장을 보내 주셔서 감사합니다. 답장을 검토하고 있습니다. 기본적으로 이해하려고합니다. 고맙습니다!! – Shvalb
이 작업을 수행하는 방법을 이해하는 데 문제가 있었기 때문에 중첩 된 .zip()을 사용하려고했으나 해결책은 완벽했습니다. 고맙습니다. – Shvalb
. 필터와 관련하여 조건이 true를 반환하면> 다음 단계로 진행하고 'false'-> 무엇보다 ?? 그것은 사슬을 끊고 그게 다 ?? 사용자에게 회신을 보내기 위해 '구독'또는 '오류'방법으로 이동하는 방법이 있습니다. – Shvalb