forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ReactiveX#225 from benjchristensen/schedulers-merge
Schedulers (merge of pull ReactiveX#199)
- Loading branch information
Showing
15 changed files
with
1,448 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2013 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package rx; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.util.functions.Action0; | ||
import rx.util.functions.Func0; | ||
|
||
/** | ||
* Represents an object that schedules units of work. | ||
*/ | ||
public interface Scheduler { | ||
|
||
/** | ||
* Schedules a cancelable action to be executed. | ||
* | ||
* @param action | ||
* action | ||
* @return a subscription to be able to unsubscribe from action. | ||
*/ | ||
Subscription schedule(Func0<Subscription> action); | ||
|
||
/** | ||
* Schedules an action to be executed. | ||
* | ||
* @param action | ||
* action | ||
* @return a subscription to be able to unsubscribe from action. | ||
*/ | ||
Subscription schedule(Action0 action); | ||
|
||
/** | ||
* Schedules an action to be executed in dueTime. | ||
* | ||
* @param action | ||
* action | ||
* @return a subscription to be able to unsubscribe from action. | ||
*/ | ||
Subscription schedule(Action0 action, long dueTime, TimeUnit unit); | ||
|
||
/** | ||
* Schedules a cancelable action to be executed in dueTime. | ||
* | ||
* @param action | ||
* action | ||
* @return a subscription to be able to unsubscribe from action. | ||
*/ | ||
Subscription schedule(Func0<Subscription> action, long dueTime, TimeUnit unit); | ||
|
||
/** | ||
* Returns the scheduler's notion of current time. | ||
*/ | ||
long now(); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
rxjava-core/src/main/java/rx/concurrency/AbstractScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright 2013 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package rx.concurrency; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.Scheduler; | ||
import rx.Subscription; | ||
import rx.subscriptions.Subscriptions; | ||
import rx.util.functions.Action0; | ||
import rx.util.functions.Func0; | ||
|
||
/* package */abstract class AbstractScheduler implements Scheduler { | ||
|
||
@Override | ||
public Subscription schedule(Action0 action) { | ||
return schedule(asFunc0(action)); | ||
} | ||
|
||
@Override | ||
public Subscription schedule(Action0 action, long dueTime, TimeUnit unit) { | ||
return schedule(asFunc0(action), dueTime, unit); | ||
} | ||
|
||
@Override | ||
public long now() { | ||
return System.nanoTime(); | ||
} | ||
|
||
private static Func0<Subscription> asFunc0(final Action0 action) { | ||
return new Func0<Subscription>() { | ||
@Override | ||
public Subscription call() { | ||
action.call(); | ||
return Subscriptions.empty(); | ||
} | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.