Skip to content

Commit 89ce9ea

Browse files
author
jmhofer
committed
added interval methods to Observable, where they were still missing
1 parent 176280e commit 89ce9ea

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.Collection;
2121
import java.util.List;
22+
import java.util.concurrent.Executors;
2223
import java.util.concurrent.Future;
2324
import java.util.concurrent.TimeUnit;
2425

@@ -36,6 +37,7 @@
3637
import rx.operators.OperationFilter;
3738
import rx.operators.OperationFinally;
3839
import rx.operators.OperationGroupBy;
40+
import rx.operators.OperationInterval;
3941
import rx.operators.OperationMap;
4042
import rx.operators.OperationMaterialize;
4143
import rx.operators.OperationMerge;
@@ -65,6 +67,7 @@
6567
import rx.operators.OperationZip;
6668
import rx.operators.SafeObservableSubscription;
6769
import rx.operators.SafeObserver;
70+
import rx.operators.OperationInterval.Interval;
6871
import rx.plugins.RxJavaErrorHandler;
6972
import rx.plugins.RxJavaObservableExecutionHook;
7073
import rx.plugins.RxJavaPlugins;
@@ -827,6 +830,35 @@ public static <T> Observable<T> synchronize(Observable<? extends T> observable)
827830
return create(OperationSynchronize.synchronize(observable));
828831
}
829832

833+
834+
/**
835+
* Emits an item each time interval (containing a sequential number).
836+
* @param interval
837+
* Interval size in time units (see below).
838+
* @param unit
839+
* Time units to use for the interval size.
840+
* @return An Observable that emits an item each time interval.
841+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229027%28v=vs.103%29.aspx">MSDN: Observable.Interval</a>
842+
*/
843+
public static Observable<Long> interval(long interval, TimeUnit unit) {
844+
return create(OperationInterval.interval(interval, unit));
845+
}
846+
847+
/**
848+
* Emits an item each time interval (containing a sequential number).
849+
* @param interval
850+
* Interval size in time units (see below).
851+
* @param unit
852+
* Time units to use for the interval size.
853+
* @param scheduler
854+
* The scheduler to use for scheduling the items.
855+
* @return An Observable that emits an item each time interval.
856+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh228911%28v=vs.103%29.aspx">MSDN: Observable.Interval</a>
857+
*/
858+
public static Observable<Long> interval(long interval, TimeUnit unit, Scheduler scheduler) {
859+
return create(OperationInterval.interval(interval, unit, scheduler));
860+
}
861+
830862
/**
831863
* Wraps each item emitted by a source Observable in a {@link Timestamped} object.
832864
* <p>

0 commit comments

Comments
 (0)