io.reactivex.Observable.firstOrError()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中io.reactivex.Observable.firstOrError()方法的一些代码示例,展示了Observable.firstOrError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.firstOrError()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:firstOrError

Observable.firstOrError介绍

[英]Returns a Single that emits only the very first item emitted by this Observable or signals a NoSuchElementException if this Observable is empty.

Scheduler: firstOrError does not operate by default on a particular Scheduler.
[中]返回一个单一值,该值仅发出此可观察对象发出的第一个项,或者如果此可观察对象为空,则发出NosTouchElementException信号。
调度程序:默认情况下,firstOrError不会在特定调度程序上运行。

代码示例

代码示例来源:origin: trello/RxLifecycle

  1. @Override
  2. public SingleSource<T> apply(Single<T> upstream) {
  3. return upstream.takeUntil(observable.firstOrError());
  4. }

代码示例来源:origin: alibaba/Tangram-Android

  1. @Override
  2. public SingleSource<T> apply(Single<T> upstream) {
  3. return upstream.takeUntil(mObservable.firstOrError());
  4. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. public Single<RxBleDeviceServices> apply(TimeoutConfiguration timeoutConf) {
  3. final ServiceDiscoveryOperation operation = operationProvider
  4. .provideServiceDiscoveryOperation(timeoutConf.timeout, timeoutConf.timeoutTimeUnit);
  5. return operationQueue.queue(operation)
  6. .firstOrError();
  7. }
  8. };

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. protected Single<RxBleDeviceServices> getCallback(RxBleGattCallback rxBleGattCallback) {
  3. return rxBleGattCallback.getOnServicesDiscovered().firstOrError()
  4. .doOnSuccess(new Consumer<RxBleDeviceServices>() {
  5. @Override
  6. public void accept(RxBleDeviceServices rxBleDeviceServices) throws Exception {
  7. bleServicesLogger.log(rxBleDeviceServices, bluetoothGatt.getDevice());
  8. }
  9. });
  10. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. public Single<byte[]> readDescriptor(@NonNull BluetoothGattDescriptor descriptor) {
  3. return operationQueue
  4. .queue(operationsProvider.provideReadDescriptor(descriptor))
  5. .firstOrError()
  6. .map(new Function<ByteAssociation<BluetoothGattDescriptor>, byte[]>() {
  7. @Override
  8. public byte[] apply(ByteAssociation<BluetoothGattDescriptor> bluetoothGattDescriptorPair) {
  9. return bluetoothGattDescriptorPair.second;
  10. }
  11. });
  12. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. public Single<byte[]> writeCharacteristic(@NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] data) {
  3. return illegalOperationChecker.checkAnyPropertyMatches(
  4. characteristic,
  5. PROPERTY_WRITE | PROPERTY_WRITE_NO_RESPONSE | PROPERTY_SIGNED_WRITE
  6. ).andThen(operationQueue.queue(operationsProvider.provideWriteCharacteristic(characteristic, data)))
  7. .firstOrError();
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void noReentrantDispose() {
  3. final AtomicInteger disposeCalled = new AtomicInteger();
  4. final BehaviorSubject<Integer> s = BehaviorSubject.create();
  5. s.doOnDispose(new Action() {
  6. @Override
  7. public void run() throws Exception {
  8. disposeCalled.incrementAndGet();
  9. s.onNext(2);
  10. }
  11. })
  12. .firstOrError()
  13. .subscribe()
  14. .dispose();
  15. assertEquals(1, disposeCalled.get());
  16. }
  17. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. protected Single<ByteAssociation<BluetoothGattDescriptor>> getCallback(RxBleGattCallback rxBleGattCallback) {
  3. return rxBleGattCallback
  4. .getOnDescriptorRead()
  5. .filter(descriptorPredicate(bluetoothGattDescriptor))
  6. .firstOrError();
  7. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  3. public Single<Integer> requestMtu(int mtu) {
  4. return operationQueue.queue(operationsProvider.provideMtuChangeOperation(mtu)).firstOrError();
  5. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorMultipleElements() {
  3. Observable.just(1, 2, 3)
  4. .firstOrError()
  5. .test()
  6. .assertNoErrors()
  7. .assertValue(1);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorOneElement() {
  3. Observable.just(1)
  4. .firstOrError()
  5. .test()
  6. .assertNoErrors()
  7. .assertValue(1);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorOneElementObservable() {
  3. Observable.just(1)
  4. .firstOrError()
  5. .toObservable()
  6. .test()
  7. .assertNoErrors()
  8. .assertValue(1);
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorMultipleElementsObservable() {
  3. Observable.just(1, 2, 3)
  4. .firstOrError()
  5. .toObservable()
  6. .test()
  7. .assertNoErrors()
  8. .assertValue(1);
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorError() {
  3. Observable.error(new RuntimeException("error"))
  4. .firstOrError()
  5. .test()
  6. .assertNoValues()
  7. .assertErrorMessage("error")
  8. .assertError(RuntimeException.class);
  9. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  3. return rxBleGattCallback
  4. .getOnDescriptorWrite()
  5. .filter(descriptorPredicate(bluetoothGattDescriptor))
  6. .firstOrError()
  7. .map(getBytesFromAssociation());
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorNoElement() {
  3. Observable.empty()
  4. .firstOrError()
  5. .test()
  6. .assertNoValues()
  7. .assertError(NoSuchElementException.class);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorErrorObservable() {
  3. Observable.error(new RuntimeException("error"))
  4. .firstOrError()
  5. .toObservable()
  6. .test()
  7. .assertNoValues()
  8. .assertErrorMessage("error")
  9. .assertError(RuntimeException.class);
  10. }
  11. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  3. return rxBleGattCallback
  4. .getOnCharacteristicWrite()
  5. .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
  6. .firstOrError()
  7. .map(getBytesFromAssociation());
  8. }

代码示例来源:origin: Polidea/RxAndroidBle

  1. @Override
  2. protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  3. return rxBleGattCallback
  4. .getOnCharacteristicRead()
  5. .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
  6. .firstOrError()
  7. .map(getBytesFromAssociation());
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void firstOrErrorNoElementObservable() {
  3. Observable.empty()
  4. .firstOrError()
  5. .toObservable()
  6. .test()
  7. .assertNoValues()
  8. .assertError(NoSuchElementException.class);
  9. }

相关文章

Observable类方法