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

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

本文整理了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

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

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

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

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

@Override
  public Single<RxBleDeviceServices> apply(TimeoutConfiguration timeoutConf) {
    final ServiceDiscoveryOperation operation = operationProvider
        .provideServiceDiscoveryOperation(timeoutConf.timeout, timeoutConf.timeoutTimeUnit);
    return operationQueue.queue(operation)
        .firstOrError();
  }
};

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

@Override
protected Single<RxBleDeviceServices> getCallback(RxBleGattCallback rxBleGattCallback) {
  return rxBleGattCallback.getOnServicesDiscovered().firstOrError()
      .doOnSuccess(new Consumer<RxBleDeviceServices>() {
        @Override
        public void accept(RxBleDeviceServices rxBleDeviceServices) throws Exception {
          bleServicesLogger.log(rxBleDeviceServices, bluetoothGatt.getDevice());
        }
      });
}

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

@Override
public Single<byte[]> readDescriptor(@NonNull BluetoothGattDescriptor descriptor) {
  return operationQueue
      .queue(operationsProvider.provideReadDescriptor(descriptor))
      .firstOrError()
      .map(new Function<ByteAssociation<BluetoothGattDescriptor>, byte[]>() {
        @Override
        public byte[] apply(ByteAssociation<BluetoothGattDescriptor> bluetoothGattDescriptorPair) {
          return bluetoothGattDescriptorPair.second;
        }
      });
}

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

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

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

@Test
  public void noReentrantDispose() {

    final AtomicInteger disposeCalled = new AtomicInteger();

    final BehaviorSubject<Integer> s = BehaviorSubject.create();
    s.doOnDispose(new Action() {
      @Override
      public void run() throws Exception {
        disposeCalled.incrementAndGet();
        s.onNext(2);
      }
    })
    .firstOrError()
    .subscribe()
    .dispose();

    assertEquals(1, disposeCalled.get());
  }
}

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

@Override
protected Single<ByteAssociation<BluetoothGattDescriptor>> getCallback(RxBleGattCallback rxBleGattCallback) {
  return rxBleGattCallback
      .getOnDescriptorRead()
      .filter(descriptorPredicate(bluetoothGattDescriptor))
      .firstOrError();
}

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

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

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

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

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

@Test
public void firstOrErrorOneElement() {
  Observable.just(1)
    .firstOrError()
    .test()
    .assertNoErrors()
    .assertValue(1);
}

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

@Test
public void firstOrErrorOneElementObservable() {
  Observable.just(1)
    .firstOrError()
    .toObservable()
    .test()
    .assertNoErrors()
    .assertValue(1);
}

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

@Test
public void firstOrErrorMultipleElementsObservable() {
  Observable.just(1, 2, 3)
    .firstOrError()
    .toObservable()
    .test()
    .assertNoErrors()
    .assertValue(1);
}

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

@Test
public void firstOrErrorError() {
  Observable.error(new RuntimeException("error"))
    .firstOrError()
    .test()
    .assertNoValues()
    .assertErrorMessage("error")
    .assertError(RuntimeException.class);
}

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

@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  return rxBleGattCallback
      .getOnDescriptorWrite()
      .filter(descriptorPredicate(bluetoothGattDescriptor))
      .firstOrError()
      .map(getBytesFromAssociation());
}

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

@Test
public void firstOrErrorNoElement() {
  Observable.empty()
    .firstOrError()
    .test()
    .assertNoValues()
    .assertError(NoSuchElementException.class);
}

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

@Test
  public void firstOrErrorErrorObservable() {
    Observable.error(new RuntimeException("error"))
      .firstOrError()
      .toObservable()
      .test()
      .assertNoValues()
      .assertErrorMessage("error")
      .assertError(RuntimeException.class);
  }
}

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

@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  return rxBleGattCallback
      .getOnCharacteristicWrite()
      .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
      .firstOrError()
      .map(getBytesFromAssociation());
}

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

@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
  return rxBleGattCallback
      .getOnCharacteristicRead()
      .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
      .firstOrError()
      .map(getBytesFromAssociation());
}

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

@Test
public void firstOrErrorNoElementObservable() {
  Observable.empty()
    .firstOrError()
    .toObservable()
    .test()
    .assertNoValues()
    .assertError(NoSuchElementException.class);
}

相关文章

Observable类方法