0

For practice purpose I created stream/Observable that emits value with 1 second period, its emitting values with one second interval but it does not terminate/stops after emitting 6, its goes on emitting values.

Observable myObservable = Observable.range(1, 6)
            .interval(5000, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread());
Jemshit
  • 9,501
  • 5
  • 69
  • 106
blackHawk
  • 6,047
  • 13
  • 57
  • 100

1 Answers1

1

interval is a static method. What you wrote is practically just Observable.interval(5000, TimeUnit.MILLISECONDS). Here is a description of the difference between static and instance methods.

There is an operator called intervalRange where you can specify the range of values you want to emit and the delay between them.

akarnokd
  • 69,132
  • 14
  • 157
  • 192
  • I understand the difference between static and instance method, wondering if it makes any difference between functionality – blackHawk Oct 17 '17 at 11:15
  • and what if I want to get desired result without intervalRange operator – blackHawk Oct 17 '17 at 11:22
  • You can use the pattern I showed in your other question: https://stackoverflow.com/a/46787816/61158, replace `StringFlowable` with `Observable.range()`. – akarnokd Oct 17 '17 at 12:14