本文整理了Java中io.reactivex.Observable.lastOrError()
方法的一些代码示例,展示了Observable.lastOrError()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.lastOrError()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:lastOrError
[英]Returns a Single that emits only the last item emitted by this Observable or signals a NoSuchElementException if this Observable is empty.
Scheduler: lastOrError does not operate by default on a particular Scheduler.
[中]返回一个仅发出此可观察对象发出的最后一项的单数,或者如果此可观察对象为空,则发出NosTouchElementException信号。
调度程序:默认情况下,lastOrError不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Object> apply(Observable<Object> o) throws Exception {
return o.lastOrError();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
return o.lastOrError().toObservable();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorOneElement() {
Observable.just(1)
.lastOrError()
.test()
.assertNoErrors()
.assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorMultipleElements() {
Observable.just(1, 2, 3)
.lastOrError()
.test()
.assertNoErrors()
.assertValue(3);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorError() {
Observable.error(new RuntimeException("error"))
.lastOrError()
.test()
.assertNoValues()
.assertErrorMessage("error")
.assertError(RuntimeException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.never().lastElement().toObservable());
TestHelper.checkDisposed(Observable.never().lastElement());
TestHelper.checkDisposed(Observable.just(1).lastOrError().toObservable());
TestHelper.checkDisposed(Observable.just(1).lastOrError());
TestHelper.checkDisposed(Observable.just(1).last(2).toObservable());
TestHelper.checkDisposed(Observable.just(1).last(2));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void lastOrErrorNoElement() {
Observable.empty()
.lastOrError()
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emptyLastOrErrorObservable() {
Observable.empty()
.lastOrError()
.toObservable()
.test()
.assertFailure(NoSuchElementException.class);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorLastOrErrorObservable() {
Observable.error(new TestException())
.lastOrError()
.toObservable()
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a CompletionStage that emits the last element of the Observable or
* NoSuchElementException if the Observable is empty.
* @param <T> the value type
* @return the Function to be used with {@code Observable.to}.
*/
public static <T> Function<Observable<T>, CompletionStage<T>> last() {
return f -> {
CompletableFuture<T> cf = new CompletableFuture<>();
f.lastOrError().subscribe(cf::complete, cf::completeExceptionally);
return cf;
};
}
代码示例来源:origin: com.microsoft.azure.v2/azure-client-runtime
Single<HttpResponse> pollUntilDone() {
return sendPollRequestWithDelay()
.repeat()
.takeUntil(new Predicate<HttpResponse>() {
@Override
public boolean test(HttpResponse ignored) {
return isDone();
}
})
.lastOrError();
}
代码示例来源:origin: com.microsoft.azure.v2/azure-client-runtime
/**
* Creates a ServiceFuture from an observable representing a long-running operation.
* @param observable The observable representing the long-running operation.
* @param callback The callback to run when the service future is completed.
* @param <T> The type of entity expected to be returned from the long-running operation.
* @return A ServiceFuture representing the long-running operation.
*/
public static <T> ServiceFuture<T> fromLRO(Observable<OperationStatus<T>> observable, ServiceCallback<T> callback) {
Single<T> single = observable.lastOrError().map(new Function<OperationStatus<T>, T>() {
@Override
public T apply(OperationStatus<T> operationStatus) {
return operationStatus.result();
}
});
return ServiceFuture.fromBody(single.toMaybe(), callback);
}
}
代码示例来源:origin: gravitee-io/graviteeio-access-management
private Single<Domain> createOrUpdateSystemScopes(Domain domain) {
return Observable.fromArray(io.gravitee.am.common.oidc.Scope.values())
.flatMapSingle(scope -> createSystemScope(domain.getId(), scope))
.lastOrError()
.map(scope -> domain);
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void test() throws Exception {
Observable<String> first = Observable.fromCallable(() -> "HEY").delay(250, TimeUnit.MILLISECONDS);
Observable<Integer> second = Observable.fromCallable(() -> 1).delay(350, TimeUnit.MILLISECONDS);
List<Observable<?>> observables = com.google.common.collect.Lists.newArrayList(first, second);
Map<Long, Object> someWeirdMapWithObject = com.google.common.collect.ImmutableMap.of(
1L, new BrandBuilder(1),
2L, new BrandBuilder(2)
);
Observable
.fromIterable(observables)
.flatMap(task -> task.observeOn(Schedulers.computation()))
// wait for all tasks to finish
.lastOrError()
.flattenAsObservable(x -> someWeirdMapWithObject.values())
.<BrandBuilder>cast(BrandBuilder.class)
.map(BrandBuilder::build)
.toList().blockingGet();
}
代码示例来源:origin: com.microsoft.azure/azure-storage-blob
}, optionsReal.parallelism())
.lastOrError();
});
代码示例来源:origin: Azure/azure-storage-java
}, optionsReal.parallelism())
.lastOrError();
});
代码示例来源:origin: gravitee-io/graviteeio-access-management
private Single<Domain> createSystemScopes(Domain domain) {
return Observable.fromArray(io.gravitee.am.common.oidc.Scope.values())
.flatMapSingle(systemScope -> {
final String scopeKey = systemScope.getKey();
NewSystemScope scope = new NewSystemScope();
scope.setKey(scopeKey);
scope.setClaims(systemScope.getClaims());
scope.setName(systemScope.getLabel());
scope.setDescription(systemScope.getDescription());
return scopeService.create(domain.getId(), scope);
})
.lastOrError()
.map(scope -> domain);
}
代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler
.flatMapMaybe(authProvider -> authenticate0(client, authentication, authProvider))
.takeUntil(userAuthentication -> userAuthentication.getUser() != null)
.lastOrError()
.flatMap(userAuthentication -> {
io.gravitee.am.identityprovider.api.User user = userAuthentication.getUser();
代码示例来源:origin: gravitee-io/graviteeio-access-management
.flatMapMaybe(authProvider -> authenticate0(client, authentication, authProvider))
.takeUntil(userAuthentication -> userAuthentication.getUser() != null)
.lastOrError()
.flatMap(userAuthentication -> {
io.gravitee.am.identityprovider.api.User user = userAuthentication.getUser();
内容来源于网络,如有侵权,请联系作者删除!