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

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

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

Observable.error介绍

[英]Returns an Observable that invokes an Observer's Observer#onError method when the Observer subscribes to it.

Scheduler: error does not operate by default on a particular Scheduler.
[中]返回一个Observable,当观察者订阅它时,它调用观察者的Observator#onError方法。
计划程序:默认情况下,错误不会在特定计划程序上运行。

代码示例

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

@Override
  public Observable<Object> apply(Throwable e) {
    return Observable.error(e);
  }
},

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

@Override
  public ObservableSource<Object> apply(Integer right) throws Exception {
    return Observable.error(new TestException());
  }
},

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

@Override
  public ObservableSource<Integer> apply(Integer v) throws Exception {
    return Observable.error(new TestException());
  }
})

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

@Override
  public ObservableSource<Integer> apply(Integer v) throws Exception {
    return Observable.error(new TestException());
  }
}));

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

@Override
  public Observable<Integer> apply(Integer t1) {
    return Observable.<Integer> error(new TestException());
  }
};

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

@Test
public void testSkipError() {
  Exception e = new Exception();
  Observable<String> ok = Observable.just("one");
  Observable<String> error = Observable.error(e);
  Observable<String> skip = Observable.concat(ok, error).skip(100);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, never()).onNext(any(String.class));
  verify(observer, times(1)).onError(e);
  verify(observer, never()).onComplete();
}

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

@Test
public void concatObservableDelayErrorTillEnd() {
  Observable.concatDelayError(
      Observable.just(Observable.just(1), Observable.just(2),
      Observable.just(3).concatWith(Observable.<Integer>error(new TestException())),
      Observable.just(4)), 2, true)
  .test()
  .assertFailure(TestException.class, 1, 2, 3, 4);
}

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

@SuppressWarnings("unchecked")
@Test
public void ambIterableOrder() {
  Observable<Integer> error = Observable.error(new RuntimeException());
  Observable.amb(Arrays.asList(Observable.just(1), error)).test().assertValue(1).assertComplete();
}

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

@Test
public void testWithError3Observable() {
  Observable<Boolean> o = Observable.sequenceEqual(
      Observable.concat(Observable.just("one"),
          Observable.<String> error(new TestException())),
      Observable.concat(Observable.just("one"),
          Observable.<String> error(new TestException()))).toObservable();
  verifyError(o);
}

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

@Test
public void testWithError1() {
  Single<Boolean> o = Observable.sequenceEqual(
      Observable.concat(Observable.just("one"),
          Observable.<String> error(new TestException())),
      Observable.just("one", "two", "three"));
  verifyError(o);
}

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

@Test
public void timedErrorOther() {
  Observable.error(new TestException())
  .timeout(1, TimeUnit.DAYS, Observable.just(1))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void error() {
  Observable.error(new TestException())
  .lastElement()
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void mainErrorDelayed() {
  Observable.<Integer>error(new TestException())
  .concatMapDelayError(new Function<Integer, ObservableSource<Integer>>() {
    @Override
    public ObservableSource<Integer> apply(Integer v) throws Exception {
      return Observable.range(v, 2);
    }
  })
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void timedError() {
  Observable.error(new TestException())
  .timeout(1, TimeUnit.DAYS)
  .test()
  .assertFailure(TestException.class);
}

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

@SuppressWarnings("unchecked")
@Test
public void errorSkip() {
  Observable.error(new TestException())
  .window(1, 2)
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void mainError() {
  Observable.error(new TestException())
  .mergeWith(Completable.complete())
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void dontRetry() {
  Observable.error(new TestException("Outer"))
  .retry(Functions.alwaysFalse())
  .test()
  .assertFailureAndMessage(TestException.class, "Outer");
}

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

@Test
public void mainError() {
  Observable.error(new TestException())
  .concatMapSingle(Functions.justFunction(Single.just(1)))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void mainError() {
  Observable.error(new TestException())
  .window(Functions.justCallable(Observable.never()))
  .test()
  .assertError(TestException.class);
}

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

@Test
@SuppressWarnings("unchecked")
public void openClosemainError() {
  Observable.error(new TestException())
  .buffer(Observable.never(), Functions.justFunction(Observable.never()))
  .test()
  .assertFailure(TestException.class);
}

相关文章

Observable类方法