Java Code Examples for io.reactivex.subjects.AsyncSubject#create()

The following examples show how to use io.reactivex.subjects.AsyncSubject#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObservableTest.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 5 votes vote down vote up
@Test
void asyncSubject_test() {

    AsyncSubject<Object> asyncSubject = AsyncSubject.create();
    asyncSubject.subscribe(x -> log("一郎神: " + x),
            Throwable::printStackTrace,
            () -> System.out.println("Emission completed"),
            disposable -> System.out.println("onSubscribe")
    );
    asyncSubject.onNext(1L);
    asyncSubject.onNext(2L);
    asyncSubject.onNext(10L);
    //asyncSubject.onError(new RuntimeException("我来耍下宝"));
    asyncSubject.onComplete();
}
 
Example 2
Source File: Demo_AsyncSubject.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	AsyncSubject<Long> asyncSubject=AsyncSubject.create();
	asyncSubject.subscribe(new Observer<Long>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("It's Done");
			
		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();
			
		}

		@Override
		public void onNext(Long value) {
			// TODO Auto-generated method stub
			System.out.println(":"+value);
		}

		@Override
		public void onSubscribe(Disposable disposable) {
			// TODO Auto-generated method stub
			System.out.println("onSubscribe");
			
		}
	});
	asyncSubject.onNext(1L);
	asyncSubject.onNext(2L);
	asyncSubject.onNext(10L);

	asyncSubject.onComplete();

}
 
Example 3
Source File: AsyncSubjectExampleActivity.java    From RxJava2-Android-Samples with Apache License 2.0 4 votes vote down vote up
private void doSomeWork() {

        AsyncSubject<Integer> source = AsyncSubject.create();

        source.subscribe(getFirstObserver()); // it will emit only 4 and onComplete

        source.onNext(1);
        source.onNext(2);
        source.onNext(3);

        /*
         * it will emit 4 and onComplete for second observer also.
         */
        source.subscribe(getSecondObserver());

        source.onNext(4);
        source.onComplete();

    }
 
Example 4
Source File: Sandbox.java    From Reactive-Android-Programming with MIT License 3 votes vote down vote up
private static void demo5() throws InterruptedException {
    Subject<String> subject = AsyncSubject.create();

    Observable.interval(0, 1, TimeUnit.SECONDS)
            .take(4)
            .map(Objects::toString)
            .subscribe(subject);

    subject.subscribe(v -> log(v));

    Thread.sleep(5100);


    subject.subscribe(v -> log(v));
}