Açıklaması şöyle
ÖrnekAsyncSubject emits only the last value of the Observable and this only happens after the Observable completes.
Elimizde şöyle bir kod olsun
AsyncSubject<Integer> pSubject = AsyncSubject.create();pSubject.onNext(0);pSubject.subscribe(it -> System.out.println("Observer 1 onNext: " + it),(Throwable error) -> { }, () -> System.out.println("Observer 1 onComplete"),on1 -> System.out.println("Observer 1 onSubscribe"));pSubject.onNext(1);pSubject.onNext(2);pSubject.subscribe(it -> System.out.println("Observer 2 onNext: " + it),(Throwable error) -> { }, () -> System.out.println("Observer 2 onComplete"),on1 -> System.out.println("Observer 2 onSubscribe"));pSubject.onNext(3);pSubject.onNext(4);/* This is very important in AsyncSubject */pSubject.onComplete();
Çıktı olarak şunu alırız
Observer 1 onSubscribeObserver 2 onSubscribeObserver 1 onNext: 4Observer 1 onCompleteObserver 2 onNext: 4Observer 2 onComplete
Hiç yorum yok:
Yorum Gönder