本文整理了Java中io.reactivex.Single.just()
方法的一些代码示例,展示了Single.just()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.just()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:just
[英]Returns a Single that emits a specified item.
To convert any object into a Single that emits that object, pass that object into the just method. Scheduler: just does not operate by default on a particular Scheduler.
[中]返回发出指定项的单个项。
要将任何对象转换为发射该对象的单个对象,请将该对象传递到just方法。调度器:只是默认情况下不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Single<Integer> call() throws Exception {
return Single.just(1);
}
}))
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v) throws Exception {
return Single.just(v);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v) throws Exception {
return Single.just(v);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v)
throws Exception {
return Single.just(v);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override public SingleSource<Integer> apply(final Integer integer) throws Exception {
if (integer == 1) {
return Single.just(2);
}
return Single.just(1);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v)
throws Exception {
return Single.just(v);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v)
throws Exception {
return Single.just(v);
}
}).subscribe(to);
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v)
throws Exception {
return Single.just(v);
}
}, 32)
代码示例来源:origin: ReactiveX/RxJava
@Override
public Single<Object> apply(Single<Object> s) throws Exception {
return Single.just((Object)1).delaySubscription(s);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Integer> apply(Integer v) throws Exception {
return Single.just(v).subscribeOn(Schedulers.computation());
}
})
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Single.just(1).flattenAsObservable(new Function<Object, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Object v) throws Exception {
return Collections.singleton(1);
}
}));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void manySources() {
Single<?>[] sources = new Single[32];
Arrays.fill(sources, Single.never());
sources[31] = Single.just(31);
Single.amb(Arrays.asList(sources))
.test()
.assertResult(31);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void hasNextCrash2() {
Single.just(1).flattenAsFlowable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
return new CrashingIterable(100, 2, 100);
}
})
.test()
.assertFailureAndMessage(TestException.class, "hasNext()", 0);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void scalar() {
Single.concat(Flowable.just(Single.just(1)))
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void selectorCrash() {
Single.just(Notification.createOnNext(1))
.dematerialize(new Function<Notification<Integer>, Notification<Integer>>() {
@Override
public Notification<Integer> apply(Notification<Integer> v) throws Exception {
throw new TestException();
}
})
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void error() {
Maybe.<Integer>error(new TestException()).switchIfEmpty(Single.just(2))
.test().assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void delaySubscriptionFlowable() throws Exception {
Single.just(1).delaySubscription(Flowable.timer(100, TimeUnit.MILLISECONDS))
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withObservableError() {
Single.just(1)
.delaySubscription(Observable.error(new TestException()))
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncFusedSingle() {
Observable.range(1, 5).hide()
.switchMap(Functions.justFunction(
Single.just(1).toObservable()
))
.test()
.assertResult(1, 1, 1, 1, 1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void delayedErrorOnSuccess() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<Integer> observer = Single.just(1)
.delay(5, TimeUnit.SECONDS, scheduler, true)
.test();
scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
observer.assertNoValues();
scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
observer.assertValue(1);
}
内容来源于网络,如有侵权,请联系作者删除!