當前位置: 首頁>>代碼示例>>Java>>正文


Java PublishSubject.onNext方法代碼示例

本文整理匯總了Java中rx.subjects.PublishSubject.onNext方法的典型用法代碼示例。如果您正苦於以下問題:Java PublishSubject.onNext方法的具體用法?Java PublishSubject.onNext怎麽用?Java PublishSubject.onNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.subjects.PublishSubject的用法示例。


在下文中一共展示了PublishSubject.onNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: basic

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void basic() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();

  subject.onCompleted();
  o.assertOnCompleted();
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:22,代碼來源:OperatorNormalizeTest.java

示例2: completion

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void completion() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  subject.onCompleted();
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertOnCompleted();
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:22,代碼來源:OperatorNormalizeTest.java

示例3: onRequestPermissionsResult

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onCompleted();
    }
}
 
開發者ID:why168,項目名稱:AndroidProjects,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例4: unsubscription

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void unsubscription() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  Subscription sub = subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  o.assertNoMoreEvents();

  sub.unsubscribe();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.assertNoMoreEvents();
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:22,代碼來源:OperatorNormalizeTest.java

示例5: overDelay_shouldEmitImmediately

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void overDelay_shouldEmitImmediately() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
  subject.onNext(1);
  o.takeNext();
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:18,代碼來源:OperatorNormalizeTest.java

示例6: should_fail_on_second_subscription

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void should_fail_on_second_subscription() {
    // given
    PublishSubject<Integer> subject = PublishSubject.create();
    Observable<Integer> limitedObservable = SubscriptionLimiter.limitSubscriptions(1, subject);
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    TestSubscriber<Integer> subscriber2 = new TestSubscriber<>();
    limitedObservable.subscribe(subscriber);
    // when
    limitedObservable.subscribe(subscriber2);
    subject.onNext(123);
    // then
    assertThat(subscriber2.getOnNextEvents()).isEmpty();
    assertThat(subscriber2.getOnErrorEvents()).hasSize(1);

}
 
開發者ID:RxHandsOn,項目名稱:MarketData,代碼行數:17,代碼來源:SubscriptionLimiterTest.java

示例7: testEmitsErrors

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void testEmitsErrors() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Throwable> result = source
    .materialize()
    .compose(Transformers.errors());

  final TestSubscriber<Throwable> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  source.onNext(1);
  resultTest.assertNoValues();

  // Only emit when an error is thrown.
  source.onError(new Throwable());
  resultTest.assertValueCount(1);
}
 
開發者ID:kickstarter,項目名稱:android-oss,代碼行數:18,代碼來源:ErrorsTransformerTest.java

示例8: Should_transmit_events_from_the_target_client

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void Should_transmit_events_from_the_target_client() {
    // given
    TestScheduler scheduler = Schedulers.test();
    PublishSubject<String> subject = PublishSubject.create();
    EventStreamClient targetClient = mock(EventStreamClient.class);
    when(targetClient.readServerSideEvents()).thenReturn(subject);
    MulticastEventStreamClient multicastEventStreamClient = new MulticastEventStreamClient(targetClient, scheduler);
    Observable<String> events = multicastEventStreamClient.readServerSideEvents();
    // when
    TestSubscriber<String> subscriber = new TestSubscriber<>();
    events.subscribe(subscriber);
    subject.onNext("Hello!");
    // then
    assertThat(subscriber.getOnNextEvents()).hasSize(1).contains("Hello!");
}
 
開發者ID:RxHandsOn,項目名稱:MarketData,代碼行數:17,代碼來源:MulticastEventStreamClientTest.java

示例9: refresh

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void refresh() throws Exception {
    final Reddit reddit = new Reddit();
    PublishSubject<Reddit> subject = PublishSubject.create();
    Mockito.doReturn(subject.asObservable().toList())
            .when(mRepository)
            .getReddits(Mockito.anyString());
    mViewModel.refresh();
    Mockito.verify(mRepository).getReddits("test");
    Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue());
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(true));
    subject.onNext(reddit);
    subject.onCompleted();
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(false));
    Assert.assertThat(mViewModel.reddits, IsCollectionContaining.hasItems(reddit));
}
 
開發者ID:DanielSerdyukov,項目名稱:droidcon2016,代碼行數:17,代碼來源:RedditListViewModelTest.java

示例10: searchQueryChange

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void searchQueryChange() throws Exception {
    final Subreddit subreddit = new Subreddit();
    PublishSubject<Subreddit> subject = PublishSubject.create();
    Mockito.doReturn(subject.asObservable().toList())
            .when(mRepository)
            .searchSubreddits(Mockito.anyString());
    mViewModel.subscribeOnSearchQueryChange();
    mViewModel.mSearchQuery.onNext("test");
    Mockito.verify(mRepository).searchSubreddits("test");
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(true));
    subject.onNext(subreddit);
    subject.onCompleted();
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(false));
    Assert.assertThat(mViewModel.subreddits, IsCollectionContaining.hasItems(subreddit));
}
 
開發者ID:DanielSerdyukov,項目名稱:droidcon2016,代碼行數:17,代碼來源:MainViewModelTest.java

示例11: testPagingCapabilities

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void testPagingCapabilities() {
    PublishSubject<Object> view = PublishSubject.create();
    BehaviorSubject<Integer> nextPageRequests = BehaviorSubject.create();
    final TestObserver<Delivery<Object, String>> testObserver = new TestObserver<>();

    nextPageRequests
        .concatMap(new Func1<Integer, Observable<Integer>>() {
            @Override
            public Observable<Integer> call(Integer targetPage) {
                return targetPage <= requestedPageCount ?
                    Observable.<Integer>never() :
                    Observable.range(requestedPageCount, targetPage - requestedPageCount);
            }
        })
        .doOnNext(new Action1<Integer>() {
            @Override
            public void call(Integer it) {
                requestedPageCount = it + 1;
            }
        })
        .startWith(Observable.range(0, requestedPageCount))
        .concatMap(new Func1<Integer, Observable<String>>() {
            @Override
            public Observable<String> call(final Integer page) {
                return requestPage(page, PAGE_SIZE);
            }
        })
        .compose(new DeliverReplay<Object, String>(view))
        .subscribe(testObserver);

    ArrayList<Delivery<Object, String>> onNext = new ArrayList<>();

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(999);
    addOnNext(onNext, 999, 0, 1, 2);

    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(2);
    addOnNext(onNext, 999, 3, 4, 5);

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(null);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(3);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    view.onNext(9999);
    addOnNext(onNext, 9999, 0, 1, 2, 3, 4, 5, 6, 7, 8);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:62,代碼來源:DeliverReplayTest.java

示例12: signOut

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
/**
 * Facebook sign out
 */
public void signOut(PublishSubject<RxStatus> statusSubject) {
    LoginManager.getInstance().logOut();
    // delete current user
    deleteCurrentUser();
    statusSubject.onNext(new RxStatus(
            CommonStatusCodes.SUCCESS,
            getString(R.string.status_success_log_out_message)
    ));
    statusSubject.onCompleted();
}
 
開發者ID:pchmn,項目名稱:RxSocialAuth,代碼行數:14,代碼來源:RxFacebookAuthFragment.java

示例13: onRequestPermissionsResult

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
public static boolean onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    final PublishSubject<Boolean> publishSubject = requestMap.get(requestCode);
    if(publishSubject == null) return false;
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        publishSubject.onNext(true);
    } else {
        publishSubject.onNext(false);
    }
    releaseRequestCode(requestCode);
    return true;
}
 
開發者ID:IronBCC,項目名稱:rx-permissions,代碼行數:12,代碼來源:RxPermissions.java

示例14: buffer

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void buffer() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  subject.onNext(2);
  subject.onNext(3);
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  o.assertNoMoreEvents();

  subject.onCompleted();
  o.assertOnCompleted();
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:32,代碼來源:OperatorNormalizeTest.java

示例15: create

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Override
public Dispatcher create(Store<T> store, Dispatcher nextDispatcher) {
    PublishSubject<Action> actions = PublishSubject.create();
    subscription = epic.run(actions, store).subscribe(store::dispatch);
    return action -> {
        nextDispatcher.dispatch(action);
        if(action instanceof Action) {
            actions.onNext((Action) action);
        }
    };
}
 
開發者ID:Yarikx,項目名稱:reductor,代碼行數:12,代碼來源:EpicMiddleware.java


注:本文中的rx.subjects.PublishSubject.onNext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。