Skip to content

Commit fdd3869

Browse files
committed
Deprecate and rename the timer methods that take initial delay and period to interval.
1 parent eccc8c4 commit fdd3869

File tree

10 files changed

+85
-23
lines changed

10 files changed

+85
-23
lines changed

src/main/java/rx/Observable.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ public final static <T> Observable<T> from(T[] array) {
12251225
* @see <a href="http://reactivex.io/documentation/operators/interval.html">ReactiveX operators documentation: Interval</a>
12261226
*/
12271227
public final static Observable<Long> interval(long interval, TimeUnit unit) {
1228-
return interval(interval, unit, Schedulers.computation());
1228+
return interval(interval, interval, unit, Schedulers.computation());
12291229
}
12301230

12311231
/**
@@ -1248,7 +1248,65 @@ public final static Observable<Long> interval(long interval, TimeUnit unit) {
12481248
* @see <a href="http://reactivex.io/documentation/operators/interval.html">ReactiveX operators documentation: Interval</a>
12491249
*/
12501250
public final static Observable<Long> interval(long interval, TimeUnit unit, Scheduler scheduler) {
1251-
return create(new OnSubscribeTimerPeriodically(interval, interval, unit, scheduler));
1251+
return interval(interval, interval, unit, scheduler);
1252+
}
1253+
1254+
/**
1255+
* Returns an Observable that emits a {@code 0L} after the {@code initialDelay} and ever increasing numbers
1256+
* after each {@code period} of time thereafter.
1257+
* <p>
1258+
* <img width="640" height="200" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/interval.p.png" alt="">
1259+
* <dl>
1260+
* <dt><b>Backpressure Support:</b></dt>
1261+
* <dd>This operator does not support backpressure as it uses time. If the downstream needs a slower rate
1262+
* it should slow the timer or use something like {@link #onBackpressureDrop}.</dd>
1263+
* <dt><b>Scheduler:</b></dt>
1264+
* <dd>{@code timer} operates by default on the {@code computation} {@link Scheduler}.</dd>
1265+
* </dl>
1266+
*
1267+
* @param initialDelay
1268+
* the initial delay time to wait before emitting the first value of 0L
1269+
* @param period
1270+
* the period of time between emissions of the subsequent numbers
1271+
* @param unit
1272+
* the time unit for both {@code initialDelay} and {@code period}
1273+
* @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after
1274+
* each {@code period} of time thereafter
1275+
* @see <a href="http://reactivex.io/documentation/operators/interval.html">ReactiveX operators documentation: Interval</a>
1276+
* @since 1.0.12
1277+
*/
1278+
public final static Observable<Long> interval(long initialDelay, long period, TimeUnit unit) {
1279+
return interval(initialDelay, period, unit, Schedulers.computation());
1280+
}
1281+
1282+
/**
1283+
* Returns an Observable that emits a {@code 0L} after the {@code initialDelay} and ever increasing numbers
1284+
* after each {@code period} of time thereafter, on a specified {@link Scheduler}.
1285+
* <p>
1286+
* <img width="640" height="200" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/interval.ps.png" alt="">
1287+
* <dl>
1288+
* <dt><b>Backpressure Support:</b></dt>
1289+
* <dd>This operator does not support backpressure as it uses time. If the downstream needs a slower rate
1290+
* it should slow the timer or use something like {@link #onBackpressureDrop}.</dd>
1291+
* <dt><b>Scheduler:</b></dt>
1292+
* <dd>you specify which {@link Scheduler} this operator will use</dd>
1293+
* </dl>
1294+
*
1295+
* @param initialDelay
1296+
* the initial delay time to wait before emitting the first value of 0L
1297+
* @param period
1298+
* the period of time between emissions of the subsequent numbers
1299+
* @param unit
1300+
* the time unit for both {@code initialDelay} and {@code period}
1301+
* @param scheduler
1302+
* the Scheduler on which the waiting happens and items are emitted
1303+
* @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after
1304+
* each {@code period} of time thereafter, while running on the given Scheduler
1305+
* @see <a href="http://reactivex.io/documentation/operators/interval.html">ReactiveX operators documentation: Interval</a>
1306+
* @since 1.0.12
1307+
*/
1308+
public final static Observable<Long> interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) {
1309+
return create(new OnSubscribeTimerPeriodically(initialDelay, period, unit, scheduler));
12521310
}
12531311

12541312
/**
@@ -2462,7 +2520,9 @@ public final static <T> Observable<T> switchOnNext(Observable<? extends Observab
24622520
* @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after
24632521
* each {@code period} of time thereafter
24642522
* @see <a href="http://reactivex.io/documentation/operators/timer.html">ReactiveX operators documentation: Timer</a>
2523+
* @deprecated use {@link #interval(long, long, TimeUnit)} instead
24652524
*/
2525+
@Deprecated
24662526
public final static Observable<Long> timer(long initialDelay, long period, TimeUnit unit) {
24672527
return timer(initialDelay, period, unit, Schedulers.computation());
24682528
}
@@ -2491,7 +2551,9 @@ public final static Observable<Long> timer(long initialDelay, long period, TimeU
24912551
* @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after
24922552
* each {@code period} of time thereafter, while running on the given Scheduler
24932553
* @see <a href="http://reactivex.io/documentation/operators/timer.html">ReactiveX operators documentation: Timer</a>
2554+
* @deprecated use {@link #interval(long, long, TimeUnit, Scheduler)} instead
24942555
*/
2556+
@Deprecated
24952557
public final static Observable<Long> timer(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) {
24962558
return create(new OnSubscribeTimerPeriodically(initialDelay, period, unit, scheduler));
24972559
}

src/perf/java/rx/operators/OperatorSerializePerf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public int getSize() {
9090
public void setup(Blackhole bh) {
9191
super.setup(bh);
9292

93-
interval = Observable.timer(0, 1, TimeUnit.MILLISECONDS).take(size).map(this);
93+
interval = Observable.interval(0, 1, TimeUnit.MILLISECONDS).take(size).map(this);
9494
}
9595
@Override
9696
public Integer call(Long t1) {

src/test/java/rx/internal/operators/OnSubscribeCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public Integer call(Long t1) {
114114

115115
Observable<Integer> source2 = source1
116116
.repeat(4)
117-
.zipWith(Observable.timer(0, 10, TimeUnit.MILLISECONDS, Schedulers.newThread()), new Func2<Integer, Long, Integer>() {
117+
.zipWith(Observable.interval(0, 10, TimeUnit.MILLISECONDS, Schedulers.newThread()), new Func2<Integer, Long, Integer>() {
118118
@Override
119119
public Integer call(Integer t1, Long t2) {
120120
return t1;

src/test/java/rx/internal/operators/OnSubscribeCombineLatestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ public void testWithCombineLatestIssue1717() throws InterruptedException {
820820
final CountDownLatch latch = new CountDownLatch(1);
821821
final AtomicInteger count = new AtomicInteger();
822822
final int SIZE = 2000;
823-
Observable<Long> timer = Observable.timer(0, 1, TimeUnit.MILLISECONDS)
823+
Observable<Long> timer = Observable.interval(0, 1, TimeUnit.MILLISECONDS)
824824
.observeOn(Schedulers.newThread())
825825
.doOnEach(new Action1<Notification<? super Long>>() {
826826

src/test/java/rx/internal/operators/OnSubscribeRefCountTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void setUp() {
4747
public void testRefCountAsync() {
4848
final AtomicInteger subscribeCount = new AtomicInteger();
4949
final AtomicInteger nextCount = new AtomicInteger();
50-
Observable<Long> r = Observable.timer(0, 5, TimeUnit.MILLISECONDS)
50+
Observable<Long> r = Observable.interval(0, 5, TimeUnit.MILLISECONDS)
5151
.doOnSubscribe(new Action0() {
5252

5353
@Override
@@ -183,7 +183,7 @@ public void call(Integer l) {
183183
public void testRepeat() {
184184
final AtomicInteger subscribeCount = new AtomicInteger();
185185
final AtomicInteger unsubscribeCount = new AtomicInteger();
186-
Observable<Long> r = Observable.timer(0, 1, TimeUnit.MILLISECONDS)
186+
Observable<Long> r = Observable.interval(0, 1, TimeUnit.MILLISECONDS)
187187
.doOnSubscribe(new Action0() {
188188

189189
@Override

src/test/java/rx/internal/operators/OnSubscribeTimerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testTimerOnce() {
6464

6565
@Test
6666
public void testTimerPeriodically() {
67-
Subscription c = Observable.timer(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(observer);
67+
Subscription c = Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(observer);
6868
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
6969

7070
InOrder inOrder = inOrder(observer);
@@ -260,7 +260,7 @@ public void onCompleted() {
260260
}
261261
@Test
262262
public void testPeriodicObserverThrows() {
263-
Observable<Long> source = Observable.timer(100, 100, TimeUnit.MILLISECONDS, scheduler);
263+
Observable<Long> source = Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler);
264264

265265
InOrder inOrder = inOrder(observer);
266266

src/test/java/rx/internal/operators/OperatorBufferTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public void bufferWithSizeSkipTake1() {
557557
}
558558
@Test(timeout = 2000)
559559
public void bufferWithTimeTake1() {
560-
Observable<Long> source = Observable.timer(40, 40, TimeUnit.MILLISECONDS, scheduler);
560+
Observable<Long> source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler);
561561

562562
Observable<List<Long>> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1);
563563

@@ -574,7 +574,7 @@ public void bufferWithTimeTake1() {
574574
}
575575
@Test(timeout = 2000)
576576
public void bufferWithTimeSkipTake2() {
577-
Observable<Long> source = Observable.timer(40, 40, TimeUnit.MILLISECONDS, scheduler);
577+
Observable<Long> source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler);
578578

579579
Observable<List<Long>> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2);
580580

@@ -593,8 +593,8 @@ public void bufferWithTimeSkipTake2() {
593593
}
594594
@Test(timeout = 2000)
595595
public void bufferWithBoundaryTake2() {
596-
Observable<Long> boundary = Observable.timer(60, 60, TimeUnit.MILLISECONDS, scheduler);
597-
Observable<Long> source = Observable.timer(40, 40, TimeUnit.MILLISECONDS, scheduler);
596+
Observable<Long> boundary = Observable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler);
597+
Observable<Long> source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler);
598598

599599
Observable<List<Long>> result = source.buffer(boundary).take(2);
600600

@@ -615,15 +615,15 @@ public void bufferWithBoundaryTake2() {
615615

616616
@Test(timeout = 2000)
617617
public void bufferWithStartEndBoundaryTake2() {
618-
Observable<Long> start = Observable.timer(61, 61, TimeUnit.MILLISECONDS, scheduler);
618+
Observable<Long> start = Observable.interval(61, 61, TimeUnit.MILLISECONDS, scheduler);
619619
Func1<Long, Observable<Long>> end = new Func1<Long, Observable<Long>>() {
620620
@Override
621621
public Observable<Long> call(Long t1) {
622-
return Observable.timer(100, 100, TimeUnit.MILLISECONDS, scheduler);
622+
return Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler);
623623
}
624624
};
625625

626-
Observable<Long> source = Observable.timer(40, 40, TimeUnit.MILLISECONDS, scheduler);
626+
Observable<Long> source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler);
627627

628628
Observable<List<Long>> result = source.buffer(start, end).take(2);
629629

@@ -693,7 +693,7 @@ public void bufferWithTimeThrows() {
693693
}
694694
@Test
695695
public void bufferWithTimeAndSize() {
696-
Observable<Long> source = Observable.timer(30, 30, TimeUnit.MILLISECONDS, scheduler);
696+
Observable<Long> source = Observable.interval(30, 30, TimeUnit.MILLISECONDS, scheduler);
697697

698698
Observable<List<Long>> result = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler).take(3);
699699

src/test/java/rx/internal/operators/OperatorObserveOnTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ public void onNext(Long t) {
663663
@Test
664664
public void testHotOperatorBackpressure() {
665665
TestSubscriber<String> ts = new TestSubscriber<String>();
666-
Observable.timer(0, 1, TimeUnit.MICROSECONDS)
666+
Observable.interval(0, 1, TimeUnit.MICROSECONDS)
667667
.observeOn(Schedulers.computation())
668668
.map(new Func1<Long, String>() {
669669

@@ -687,7 +687,7 @@ public String call(Long t1) {
687687

688688
@Test
689689
public void testErrorPropagatesWhenNoOutstandingRequests() {
690-
Observable<Long> timer = Observable.timer(0, 1, TimeUnit.MICROSECONDS)
690+
Observable<Long> timer = Observable.interval(0, 1, TimeUnit.MICROSECONDS)
691691
.doOnEach(new Action1<Notification<? super Long>>() {
692692

693693
@Override

src/test/java/rx/internal/operators/OperatorPublishTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void call() {
247247
@Test
248248
public void testConnectWithNoSubscriber() {
249249
TestScheduler scheduler = new TestScheduler();
250-
ConnectableObservable<Long> co = Observable.timer(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish();
250+
ConnectableObservable<Long> co = Observable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish();
251251
co.connect();
252252
// Emit 0
253253
scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);

src/test/java/rx/internal/producers/ProducersTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ public void testObserverArbiterAsync() {
355355
TestScheduler test = Schedulers.test();
356356
@SuppressWarnings("unchecked")
357357
List<Observable<Long>> timers = Arrays.asList(
358-
Observable.timer(100, 100, TimeUnit.MILLISECONDS, test),
359-
Observable.timer(100, 100, TimeUnit.MILLISECONDS, test)
358+
Observable.interval(100, 100, TimeUnit.MILLISECONDS, test),
359+
Observable.interval(100, 100, TimeUnit.MILLISECONDS, test)
360360
.map(plus(20)),
361-
Observable.timer(100, 100, TimeUnit.MILLISECONDS, test)
361+
Observable.interval(100, 100, TimeUnit.MILLISECONDS, test)
362362
.map(plus(40))
363363
);
364364

0 commit comments

Comments
 (0)