rx.Observable.amb()方法的使用及代码示例

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

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

Observable.amb介绍

[英]Mirrors the one Observable in an Iterable of several Observables that first emits an item.

Scheduler: amb does not operate by default on a particular Scheduler.
[中]镜像首先发射一个项目的多个可观察对象中的一个可观察对象。
调度器:默认情况下,amb不会在特定的调度器上运行。

代码示例

代码示例来源:origin: com.netflix.rxjava/rxjava-core

/**
 * Mirrors the first Observable (current or provided) that emits an item.
 * <p>
 * <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * 
 * @param t1
 *            an Observable competing to react first
 * @return an Observable that emits the same sequence of items as whichever of the source Observables first
 *         emitted an item
 * @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
 * @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
 * @since 0.20
 */
public final Observable<T> ambWith(Observable<? extends T> t1) {
  return amb(this, t1);
}

代码示例来源:origin: henrymorgen/android-advanced-light

private void amb() {
  Observable.amb(Observable.just(1,2,3).delay(2, TimeUnit.SECONDS),Observable.just(4,5,6))
      .subscribe(new Action1<Integer>() {
    @Override
    public void call(Integer integer) {
      Log.d(TAG, "amb:"+integer);
    }
  });
}

代码示例来源:origin: leeowenowen/rxjava-examples

@Override
public void run() {
 Observable.amb(Observable.create(new Observable.OnSubscribe<Integer>() {
          @Override
          public void call(Subscriber<? super Integer> subscriber) {

代码示例来源:origin: CasterIO/RxExamples

@OnClick(R.id.amb_execute)
public void onExecuteClick(final View v) {
  killThreads();
  Observable.amb(getCustomerFromServerOne(), getCustomerFromServerTwo())
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnSubscribe(new Action0() {
        @Override
        public void call() {
          v.setEnabled(false);
        }
      })
      .subscribe(new Subscriber<Customer>() {
        @Override
        public void onCompleted() {
        }
        @Override
        public void onError(Throwable e) {
          Log.d("AMB", e.getMessage(), e);
        }
        @Override
        public void onNext(Customer customer) {
          Log.d("AMB", customer.getName());
          results.setText(results.getText() + "\n" + customer.getName());
          unsubscribe();
          v.setEnabled(true);
        }
      });
}

代码示例来源:origin: akarnokd/akarnokd-misc

@Test
  public void test() throws Exception {
    Observable<Object> obs1 = Observable
        .<Object>just("obs 1 event")
        .doOnSubscribe(() -> System.out.println("obs1 sub"))
        .doOnUnsubscribe(() -> System.out.println("obs1 unsub"));

    Observable<Object> obs2 = Observable
        .<Object>just("obs 2 event")
        .doOnSubscribe(() -> System.out.println("obs2 sub"))
        .doOnUnsubscribe(() -> System.out.println("obs2 unsub"));

    Observable
        .amb(obs1, obs2)
        .subscribe(System.out::println);

    Thread.sleep(500);
  }
}

代码示例来源:origin: nurkiewicz/rxjava-book-examples

@Test
public void sample_375() throws Exception {
  Observable.amb(
      stream(100, 17, "S"),
      stream(200, 10, "F")
  ).subscribe(log::info);
}

相关文章

Observable类方法