当前位置: 首页>>代码示例>>Java>>正文


Java ReplaySubject.onNext方法代码示例

本文整理汇总了Java中io.reactivex.subjects.ReplaySubject.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java ReplaySubject.onNext方法的具体用法?Java ReplaySubject.onNext怎么用?Java ReplaySubject.onNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.subjects.ReplaySubject的用法示例。


在下文中一共展示了ReplaySubject.onNext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSomeWork

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
private void doSomeWork() {

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

        source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4

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

        /*
         * it will emit 1, 2, 3, 4 for second observer also as we have used replay
         */
        source.subscribe(getSecondObserver());

    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ReplaySubjectExampleActivity.java

示例2: doSomeWork

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
/**
 * ReplaySubject会发射所有来自原始Observable的数据给观察者,无论它们是何时订阅的。
 * 也有其它版本的ReplaySubject,在重放缓存增长到一定大小的时候或过了一段时间后会丢弃旧的数据(原始Observable发射的)。
 *
 * 如果你把ReplaySubject当作一个观察者使用,注意不要从多个线程中调用它的onNext方法(包括其它的on系列方法),
 * 这可能导致同时(非顺序)调用,这会违反Observable协议, 给Subject的结果增加了不确定性。
 */
private void doSomeWork() {

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

    source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4

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

    /*
     * it will emit 1, 2, 3, 4 for second observer also as we have used replay
     */
    source.subscribe(getSecondObserver());

}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:26,代码来源:ReplaySubjectExampleActivity.java

示例3: testUnsubscribeBeforeEmit

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test public void testUnsubscribeBeforeEmit() {
  TestObserver<String> observer = new TestObserver<>();
  ReplaySubject<String> subject = ReplaySubject.create();
  SubscriptionProxy<String> proxy = SubscriptionProxy.create(subject);

  proxy.subscribe(observer);
  proxy.dispose();

  observer.assertNotComplete();
  observer.assertNoValues();

  subject.onNext("Avanti!");
  subject.onComplete();

  // disposable observables may not be resused in RxJava2
  observer = new TestObserver<>();
  proxy.subscribe(observer);
  observer.assertComplete();
  observer.assertValue("Avanti!");
}
 
开发者ID:airbnb,项目名称:RxGroups,代码行数:21,代码来源:SubscriptionProxyTest.java

示例4: shouldCacheResultsWhileUnsubscribedAndDeliverAfterResubscription

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test public void shouldCacheResultsWhileUnsubscribedAndDeliverAfterResubscription() {
  TestObserver<String> observer = new TestObserver<>();
  ReplaySubject<String> subject = ReplaySubject.create();
  SubscriptionProxy<String> proxy = SubscriptionProxy.create(subject);

  proxy.subscribe(observer);
  proxy.dispose();

  observer.assertNoValues();

  subject.onNext("Avanti!");
  subject.onComplete();

  // disposable observables may not be resused in RxJava2
  observer = new TestObserver<>();
  proxy.subscribe(observer);

  observer.awaitTerminalEvent(3, TimeUnit.SECONDS);
  observer.assertValue("Avanti!");
}
 
开发者ID:airbnb,项目名称:RxGroups,代码行数:21,代码来源:SubscriptionProxyTest.java

示例5: shouldRedeliverSameResultsToDifferentSubscriber

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test public void shouldRedeliverSameResultsToDifferentSubscriber() {
  // Use case: When rotating an activity, ObservableManager will re-subscribe original request's
  // Observable to a new Observer, which is a member of the new activity instance. In this
  // case, we may want to redeliver any previous results (if the request is still being
  // managed by ObservableManager).
  TestObserver<String> observer = new TestObserver<>();
  ReplaySubject<String> subject = ReplaySubject.create();
  SubscriptionProxy<String> proxy = SubscriptionProxy.create(subject);

  proxy.subscribe(observer);

  subject.onNext("Avanti!");
  subject.onComplete();

  proxy.dispose();

  TestObserver<String> newSubscriber = new TestObserver<>();
  proxy.subscribe(newSubscriber);

  newSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
  newSubscriber.assertComplete();
  newSubscriber.assertValue("Avanti!");

  observer.assertComplete();
  observer.assertValue("Avanti!");
}
 
开发者ID:airbnb,项目名称:RxGroups,代码行数:27,代码来源:SubscriptionProxyTest.java

示例6: shouldKeepDeliveringEventsAfterResubscribed

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
@Test public void shouldKeepDeliveringEventsAfterResubscribed() {
  TestObserver<String> observer = new TestObserver<>();
  ReplaySubject<String> subject = ReplaySubject.create();
  SubscriptionProxy<String> proxy = SubscriptionProxy.create(subject);

  proxy.subscribe(observer);
  subject.onNext("Avanti 1");
  proxy.dispose();
  observer = new TestObserver<>();
  proxy.subscribe(observer);

  subject.onNext("Avanti!");

  observer.assertValues("Avanti 1", "Avanti!");
}
 
开发者ID:airbnb,项目名称:RxGroups,代码行数:16,代码来源:SubscriptionProxyTest.java

示例7: main

import io.reactivex.subjects.ReplaySubject; //导入方法依赖的package包/类
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observer<Long> observer=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");
			
		}
	};
	
	ReplaySubject<Long> replaySubject=ReplaySubject.create();
	replaySubject.onNext(1l);
	replaySubject.onNext(2l);
	replaySubject.subscribe(observer);
	replaySubject.onNext(10l);
	replaySubject.onComplete();
	

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:42,代码来源:Demo_ReplaySubject.java


注:本文中的io.reactivex.subjects.ReplaySubject.onNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。