Rxjava 简明教程

RxJava - Creating Observables

以下是可以创建可观察序列的基类。

Following are the base classes to create observables.

  1. Flowable − 0..N flows, Emits 0 or n items. Supports Reactive-Streams and back-pressure.

  2. Observable − 0..N flows ,but no back-pressure.

  3. Single − 1 item or error. Can be treated as a reactive version of method call.

  4. Completable − No item emitted. Used as a signal for completion or error. Can be treated as a reactive version of Runnable.

  5. MayBe − Either No item or 1 item emitted. Can be treated as a reactive version of Optional.

以下是 Observable 类中创建可观察序列的便利方法。

Following are the convenient methods to create observables in Observable class.

  1. just(T item) − Returns an Observable that signals the given (constant reference) item and then completes.

  2. fromIterable(Iterable source) − Converts an Iterable sequence into an ObservableSource that emits the items in the sequence.

  3. fromArray(T…​ items) − Converts an Array into an ObservableSource that emits the items in the Array.

  4. fromCallable(Callable supplier) − Returns an Observable that, when an observer subscribes to it, invokes a function you specify and then emits the value returned from that function.

  5. fromFuture(Future future) − Converts a Future into an ObservableSource.

  6. interval(long initialDelay, long period, TimeUnit unit) − Returns an Observable that emits a 0L after the initialDelay and ever increasing numbers after each period of time thereafter.