RxJava Tutorial on RxJava Creating Observables

following are the base classes to create observables.

  • flowable − 0..n flows, emits 0 or n items. supports reactive-streams and back-pressure.

  • observable − 0..n flows ,but no back-pressure.

  • single − 1 item or error. can be treated as a reactive version of method call.

  • completable − no item emitted. used as a signal for completion or error. can be treated as a reactive version of runnable.

  • maybe − either no item or 1 item emitted. can be treated as a reactive version of optional.

following are the convenient methods to create observables in observable class.

  • just(t item) − returns an observable that signals the given (constant reference) item and then completes.

  • fromiterable(iterable source) − converts an iterable sequence into an observablesource that emits the items in the sequence.

  • fromarray(t... items) − converts an array into an observablesource that emits the items in the array.

  • 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.

  • fromfuture(future future) − converts a future into an observablesource.

  • 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.