本文整理汇总了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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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!");
}
示例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));
}
示例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));
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
};
}