Skip to content

Commit 504bd05

Browse files
author
jmhofer
committed
fixing the scheduler methods to fit the new pattern
1 parent cd18923 commit 504bd05

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

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

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public abstract class Scheduler {
7171
*/
7272
public abstract <T> Subscription schedule(T state, Func2<Scheduler, T, Subscription> action, long delayTime, TimeUnit unit);
7373

74+
/**
75+
* Schedules a cancelable action to be executed periodically.
76+
*
77+
* @param state State to pass into the action.
78+
* @param action The action to execute periodically.
79+
* @param initialDelay Time to wait before executing the action for the first time.
80+
* @param period The time interval to wait each time in between executing the action.
81+
* @param unit The time unit the interval above is given in.
82+
* @return A subscription to be able to unsubscribe from action.
83+
*/
84+
public abstract <T> Subscription schedulePeriodically(T state, Func2<Scheduler, T, Subscription> action, long initialDelay, long period, TimeUnit unit);
85+
7486
/**
7587
* Schedules a cancelable action to be executed at dueTime.
7688
*
@@ -103,7 +115,7 @@ public Subscription schedule(final Func1<Scheduler, Subscription> action) {
103115
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
104116

105117
@Override
106-
public Subscription call(Scheduler scheduler, Void t2) {
118+
public Subscription call(Scheduler scheduler, @SuppressWarnings("unused") Void state) {
107119
return action.call(scheduler);
108120
}
109121
});
@@ -120,7 +132,7 @@ public Subscription schedule(final Func0<Subscription> action) {
120132
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
121133

122134
@Override
123-
public Subscription call(Scheduler scheduler, Void t2) {
135+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
124136
return action.call();
125137
}
126138
});
@@ -137,7 +149,7 @@ public Subscription schedule(final Action0 action) {
137149
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
138150

139151
@Override
140-
public Subscription call(Scheduler scheduler, Void t2) {
152+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
141153
action.call();
142154
return Subscriptions.empty();
143155
}
@@ -159,7 +171,7 @@ public Subscription schedule(final Func1<Scheduler, Subscription> action, long d
159171
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
160172

161173
@Override
162-
public Subscription call(Scheduler scheduler, Void t2) {
174+
public Subscription call(Scheduler scheduler, @SuppressWarnings("unused") Void state) {
163175
return action.call(scheduler);
164176
}
165177
}, delayTime, unit);
@@ -176,7 +188,7 @@ public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit
176188
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
177189

178190
@Override
179-
public Subscription call(Scheduler scheduler, Void t2) {
191+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
180192
action.call();
181193
return Subscriptions.empty();
182194
}
@@ -194,23 +206,12 @@ public Subscription schedule(final Func0<Subscription> action, long delayTime, T
194206
return schedule(null, new Func2<Scheduler, Void, Subscription>() {
195207

196208
@Override
197-
public Subscription call(Scheduler scheduler, Void t2) {
209+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
198210
return action.call();
199211
}
200212
}, delayTime, unit);
201213
}
202214

203-
/**
204-
* Schedules an action to be executed periodically.
205-
*
206-
* @param action The action to execute periodically.
207-
* @param initialDelay Time to wait before executing the action for the first time.
208-
* @param period The time interval to wait each time in between executing the action.
209-
* @param unit The time unit the interval above is given in.
210-
* @return A subscription to be able to unsubscribe from action.
211-
*/
212-
Subscription schedulePeriodically(Action0 action, long initialDelay, long period, TimeUnit unit);
213-
214215
/**
215216
* Schedules a cancelable action to be executed periodically.
216217
*
@@ -220,7 +221,14 @@ public Subscription call(Scheduler scheduler, Void t2) {
220221
* @param unit The time unit the interval above is given in.
221222
* @return A subscription to be able to unsubscribe from action.
222223
*/
223-
Subscription schedulePeriodically(Func0<Subscription> action, long initialDelay, long period, TimeUnit unit);
224+
public Subscription schedulePeriodically(final Func1<Scheduler, Subscription> action, long initialDelay, long period, TimeUnit unit) {
225+
return schedulePeriodically(null, new Func2<Scheduler, Void, Subscription>() {
226+
@Override
227+
public Subscription call(Scheduler scheduler, @SuppressWarnings("unused") Void state) {
228+
return action.call(scheduler);
229+
}
230+
}, initialDelay, period, unit);
231+
}
224232

225233
/**
226234
* Schedules a cancelable action to be executed periodically.
@@ -231,19 +239,33 @@ public Subscription call(Scheduler scheduler, Void t2) {
231239
* @param unit The time unit the interval above is given in.
232240
* @return A subscription to be able to unsubscribe from action.
233241
*/
234-
Subscription schedulePeriodically(Func1<Scheduler, Subscription> action, long initialDelay, long period, TimeUnit unit);
242+
public Subscription schedulePeriodically(final Func0<Subscription> action, long initialDelay, long period, TimeUnit unit) {
243+
return schedulePeriodically(null, new Func2<Scheduler, Void, Subscription>() {
244+
@Override
245+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
246+
return action.call();
247+
}
248+
}, initialDelay, period, unit);
249+
}
235250

236251
/**
237-
* Schedules a cancelable action to be executed periodically.
238-
*
239-
* @param state State to pass into the action.
252+
* Schedules an action to be executed periodically.
253+
*
240254
* @param action The action to execute periodically.
241255
* @param initialDelay Time to wait before executing the action for the first time.
242256
* @param period The time interval to wait each time in between executing the action.
243257
* @param unit The time unit the interval above is given in.
244258
* @return A subscription to be able to unsubscribe from action.
245259
*/
246-
<T> Subscription schedulePeriodically(T state, Func2<Scheduler, T, Subscription> action, long initialDelay, long period, TimeUnit unit);
260+
public Subscription schedulePeriodically(final Action0 action, long initialDelay, long period, TimeUnit unit) {
261+
return schedulePeriodically(null, new Func2<Scheduler, Void, Subscription>() {
262+
@Override
263+
public Subscription call(@SuppressWarnings("unused") Scheduler scheduler, @SuppressWarnings("unused") Void state) {
264+
action.call();
265+
return Subscriptions.empty();
266+
}
267+
}, initialDelay, period, unit);
268+
}
247269

248270
/**
249271
* Returns the scheduler's notion of current absolute time in milliseconds.

0 commit comments

Comments
 (0)