本文整理了Java中io.reactivex.Flowable.lastOrError()
方法的一些代码示例,展示了Flowable.lastOrError()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.lastOrError()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:lastOrError
[英]Returns a Single that emits only the last item emitted by this Flowable or signals a NoSuchElementException if this Flowable is empty.
Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., without applying backpressure). Scheduler: lastOrError does not operate by default on a particular Scheduler.
[中]返回仅发出此可流动项发出的最后一项的单个项,或者如果此可流动项为空,则发出NosTouchElementException信号。
背压:操作员接受来自下游的背压,并以无限制的方式(即不施加背压)消耗源发布服务器。调度程序:默认情况下,lastOrError不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Object> apply(Flowable<Object> f) throws Exception {
return f.lastOrError();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Flowable<Object> f) throws Exception {
return f.lastOrError().toFlowable();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorError() {
Flowable.error(new RuntimeException("error"))
.lastOrError()
.test()
.assertNoValues()
.assertErrorMessage("error")
.assertError(RuntimeException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorOneElement() {
Flowable.just(1)
.lastOrError()
.test()
.assertNoErrors()
.assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emptyLastOrErrorFlowable() {
Flowable.empty()
.lastOrError()
.toFlowable()
.test()
.assertFailure(NoSuchElementException.class);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorNoElement() {
Flowable.empty()
.lastOrError()
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorMultipleElements() {
Flowable.just(1, 2, 3)
.lastOrError()
.test()
.assertNoErrors()
.assertValue(3);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorLastOrErrorFlowable() {
Flowable.error(new TestException())
.lastOrError()
.toFlowable()
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Flowable.never().lastElement().toFlowable());
TestHelper.checkDisposed(Flowable.never().lastElement());
TestHelper.checkDisposed(Flowable.just(1).lastOrError().toFlowable());
TestHelper.checkDisposed(Flowable.just(1).lastOrError());
TestHelper.checkDisposed(Flowable.just(1).last(2).toFlowable());
TestHelper.checkDisposed(Flowable.just(1).last(2));
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a CompletionStage that emits the last element of the Flowable or
* NoSuchElementException if the Flowable is empty.
* @param <T> the value type
* @return the Function to be used with {@code Flowable.to}.
*/
public static <T> Function<Flowable<T>, CompletionStage<T>> last() {
return f -> {
CompletableFuture<T> cf = new CompletableFuture<>();
f.lastOrError().subscribe(cf::complete, cf::completeExceptionally);
return cf;
};
}
代码示例来源:origin: com.github.davidmoten/rxjava2-jdbc
@SuppressWarnings("unchecked")
private Single<TxWithoutValue> build() {
return Single.defer(() -> {
AtomicReference<Connection> con = new AtomicReference<Connection>();
// set the atomic reference when transactedConnection emits
Single<Connection> transactedConnection = b.connection //
.map(c -> Util.toTransactedConnection(con, c));
return Call //
.createWithZeroOutParameters(transactedConnection, b.sql, parameterGroups(), b.params) //
.materialize() //
.filter(x -> !x.isOnNext()) //
.<TxWithoutValue>flatMap(n -> Tx.toTx(n, con.get(), b.db)) //
.doOnNext(tx -> {
if (tx.isComplete()) {
((TxImpl<Object>) tx).connection().commit();
}
}) //
.lastOrError();
});
}
代码示例来源:origin: davidmoten/rxjava2-jdbc
@SuppressWarnings("unchecked")
private Single<TxWithoutValue> build() {
return Single.defer(() -> {
AtomicReference<Connection> con = new AtomicReference<Connection>();
// set the atomic reference when transactedConnection emits
Single<Connection> transactedConnection = b.connection //
.map(c -> Util.toTransactedConnection(con, c));
return Call //
.createWithZeroOutParameters(transactedConnection, b.sql, parameterGroups(), b.params) //
.materialize() //
.filter(x -> !x.isOnNext()) //
.<TxWithoutValue>flatMap(n -> Tx.toTx(n, con.get(), b.db)) //
.doOnNext(tx -> {
if (tx.isComplete()) {
((TxImpl<Object>) tx).connection().commit();
}
}) //
.lastOrError();
});
}
内容来源于网络,如有侵权,请联系作者删除!