Skip to content

Commit 700e91d

Browse files
Merge pull request #356 from jmhofer/interval
Added interval methods to Observable, where they were still missing
2 parents 6365f88 + 367eb22 commit 700e91d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import rx.operators.OperationFilter;
3838
import rx.operators.OperationFinally;
3939
import rx.operators.OperationGroupBy;
40+
import rx.operators.OperationInterval;
4041
import rx.operators.OperationMap;
4142
import rx.operators.OperationMaterialize;
4243
import rx.operators.OperationMerge;
@@ -830,6 +831,35 @@ public static <T> Observable<T> synchronize(Observable<? extends T> observable)
830831
return create(OperationSynchronize.synchronize(observable));
831832
}
832833

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

0 commit comments

Comments
 (0)