-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schedulers (merge of pull #199) #225
Schedulers (merge of pull #199) #225
Conversation
ExecutorScheduler throws exception for the delayed action.
…edulers-merge Conflicts: rxjava-core/src/main/java/rx/Observable.java
For now keeping ScheduledObserver an implementation detail until it's clear we want it part of the long-term public API.
ScheduledExecutorScheduler is just an extension of ExecutorScheduler so keeping them together for less surface area on the API.
Until there is a use case other than unit testing I'm moving this to a non-public role so it's not part of the public API.
- added Javadocs - moved some classes to package-private until they are proven necessary for the public API - made ExecutorScheduler support Executor implementations and still work with time delays by using a system-wide scheduler/timer - made IO thread-pool unbounded with a cached thread pool
- I plan on using this to expand unit testing around various aspects of schedulers - this is not done as an inner-class as it does not correlate with just one class but is cross-functional over many classes thus it fits best here
RxJava-pull-requests #77 SUCCESS |
RxJava-pull-requests #78 FAILURE |
- the list of operators to add overloads to was derived from the Rx.Net docs at http://msdn.microsoft.com/en-us/library/hh212048(v=vs.103).aspx
The unit test is poorly written (non-deterministic). I'll fix in the morning. |
Awesome work! - With this, it should be easy to implement operators like "sample" etc. |
- This applies to any pools RxJava itself creates. It will be up to users to do this for Executors they inject.
Yes it should open the gates to many operators we haven't been able to pursue. |
… considering very long running app with lots of IO events.
Committed a few tweaks and fixes. Open questions for me are:
|
Can someone with an Rx.Net environment setup implement a test similar to this from Java and tell me the output? @Test
public void testMixedSchedulers() throws InterruptedException {
final String mainThreadName = Thread.currentThread().getName();
Observable<String> o = Observable.<String> create(new Func1<Observer<String>, Subscription>() {
@Override
public Subscription call(Observer<String> observer) {
System.out.println("Origin observable is running on: " + Thread.currentThread().getName());
assertFalse(Thread.currentThread().getName().equals(mainThreadName));
assertTrue("Actually: " + Thread.currentThread().getName(), Thread.currentThread().getName().startsWith("RxIOThreadPool"));
observer.onNext("one");
observer.onNext("two");
observer.onNext("three");
observer.onCompleted();
return Subscriptions.empty();
}
}).subscribeOn(Schedulers.threadPoolForIO()); // subscribe to the source on the IO thread pool
// now merge on the CPU threadpool
o = Observable.<String> merge(o, Observable.<String> from("four", "five"))
.subscribeOn(Schedulers.threadPoolForComputation())
.map(new Func1<String, String>() {
@Override
public String call(String v) {
// opportunity to see what thread the merge is running on
System.out.println("Merge is running on: " + Thread.currentThread().getName());
return v;
}
});
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<RuntimeException> onError = new AtomicReference<RuntimeException>();
// subscribe on a new thread
o.subscribe(new Observer<String>() {
@Override
public void onCompleted() {
System.out.println("==> received onCompleted");
latch.countDown();
}
@Override
public void onError(Exception e) {
System.out.println("==> received onError: " + e.getMessage());
onError.set((RuntimeException) e);
latch.countDown();
}
@Override
public void onNext(String v) {
System.out.println("==> Final subscribe is running on: " + Thread.currentThread().getName());
System.out.println("==> onNext: " + v);
}
}, Schedulers.newThread());
// wait for the above to finish or blow up if it's blocked
latch.await(5, TimeUnit.SECONDS);
} I'm trying to understand how a sequence should work when multiple Of course Rx.Net doesn't have the IO and CPU thread pools ... those are just helper methods to Executors which would be 2 separate threadpools for different work types so you'll need to adjust that. |
RxJava-pull-requests #79 SUCCESS |
Is there any reason to use For example, on a method overload of return merge(source).subscribeOn(scheduler); or is there some reason to inside the return scheduler.schedule(new Func0<Subscription>() {
@Override
public Subscription call() {
return new MergeObservable<T>(o).call(observer);
}
}); They seem to accomplish the same thing but would like to know if there's a reason to prefer one over the other. I prefer just reusing I can't tell from reading C# code what it does as I can't find the extensions that implement the override methods! |
/** | ||
* Schedules an action to be executed in dueTime. | ||
* | ||
* @param action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add param for dueTime
I'm pulling the trigger and merging this into master so people can start playing with it and providing feedback. The public API changes are fairly limited still so most changes (which I fully expect) will be implementation details. |
Schedulers (merge of pull #199)
I have some outstanding questions on how these should be implemented (or even why we need them when the 'subscribeOn' operator is far cleaner) so want to remove them for now so they don't make it into the public incorrectly.
RxJava-pull-requests #80 SUCCESS |
Schedulers (merge of pull ReactiveX#199)
Manual merge of #199 by @mairbek plus the following changes:
Next step from here is to review all operator implementations and add the Scheduler overloads.