RxJava로 리 액티브 프로그래밍을 배우고 단일 실행 스레드에서 마우스 블로킹과 동시에 emmited 값을 소비하려고합니다.옵저버가 동시에 소모 한 값 소모
Observable
.interval(50, TimeUnit.MILLISECONDS)
.take(5)
.subscribe(new Action1<Long>() {
@Override
public void call(Long counter) {
sleep(1000);
System.out.println("Got: " + counter + " thread : "+ Thread.currentThread().getName());
}
});
sleep(10000);
나는
Got: 0 thread : RxComputationThreadPool-1
Got: 1 thread : RxComputationThreadPool-1
Got: 2 thread : RxComputationThreadPool-1
Got: 3 thread : RxComputationThreadPool-1
Got: 4 thread : RxComputationThreadPool-1
가 어떻게 비동기의 각 이벤트를 처리 할이 출력을 얻을 것이다? 수신이
Got: 0 thread : RxComputationThreadPool-1
Got: 1 thread : RxComputationThreadPool-2
Got: 2 thread : RxComputationThreadPool-3
Got: 3 thread : RxComputationThreadPool-4
Got: 4 thread : RxComputationThreadPool-5
원하는 동작을 얻으려면 내가해야 할 변경 사항을 제안 할 수 있습니까? 실제 예제로 이해하는 것이 훨씬 쉬울 것이라고 생각합니다 ... – vach
죄송합니다, Java는 모르지만 .NET에서는'xs.FlatMap (x => ProcessAsync (x))와 유사합니다.)'이며, 여기서'ProcessAsync'는'x'를 인수로 받아들이고 어떤 타입의 관찰 가능을 반환하는 메소드입니다. 'ProcessAsync'에 대한 각 호출의 반환 값을 처리 할 필요가 없다고 가정하면 부작용만을위한 매개 변수없이'Subscribe'를 호출 할 수도 있습니다. –
몇 가지 추가 정보를 포함하도록 답변을 업데이트했습니다. –