-
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
2.x: RxJavaPlugins unwrapRunnable #5734
Changes from 1 commit
d0589d4
3be3fa0
f8ef988
e862c1f
07cbd46
31ff1e9
d5c2166
a75a7f1
b47fcd8
c0d6c78
f63a799
1db27f8
9703201
a5a7ce0
ebe2ca8
b2f0c86
bf72b36
171ac80
19eba48
2a8e6f0
f1af3f7
a1c5ad1
ac5c3f5
3c8aefd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* 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 io.reactivex.internal.schedulers; | ||
|
||
public interface SchedulerRunnableWrapper extends Runnable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document this interface a bit and include a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not certain this should extend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chaged it. |
||
|
||
Runnable getWrappedRunnable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a short description of this method and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -620,6 +620,18 @@ public static void setSingleSchedulerHandler(@Nullable Function<? super Schedule | |
onSingleHandler = handler; | ||
} | ||
|
||
/** | ||
* Unwraps internal scheduler's task. | ||
* @param task the internal task | ||
* @return the unwrapped runnable or task | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alos please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
public static Runnable unwrapRunnable(Runnable task) { | ||
if (task instanceof SchedulerRunnableWrapper) { | ||
return ((SchedulerRunnableWrapper) task).getWrappedRunnable(); | ||
} | ||
return task; | ||
} | ||
|
||
/** | ||
* Revokes the lockdown, only for testing purposes. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,26 +16,16 @@ | |
|
||
package io.reactivex.plugins; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.*; | ||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import java.lang.reflect.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.concurrent.atomic.*; | ||
|
||
import org.junit.*; | ||
import org.reactivestreams.*; | ||
|
||
import io.reactivex.*; | ||
import io.reactivex.Observable; | ||
import io.reactivex.Observer; | ||
import io.reactivex.Scheduler.Worker; | ||
import io.reactivex.disposables.*; | ||
import io.reactivex.disposables.Disposable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't unroll star imports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
import io.reactivex.disposables.Disposables; | ||
import io.reactivex.exceptions.*; | ||
import io.reactivex.flowables.ConnectableFlowable; | ||
import io.reactivex.functions.*; | ||
import io.reactivex.functions.BiFunction; | ||
import io.reactivex.functions.BooleanSupplier; | ||
import io.reactivex.functions.Consumer; | ||
import io.reactivex.functions.Function; | ||
import io.reactivex.internal.functions.Functions; | ||
import io.reactivex.internal.operators.completable.CompletableError; | ||
import io.reactivex.internal.operators.flowable.FlowableRange; | ||
|
@@ -44,10 +34,30 @@ | |
import io.reactivex.internal.operators.parallel.ParallelFromPublisher; | ||
import io.reactivex.internal.operators.single.SingleJust; | ||
import io.reactivex.internal.schedulers.ImmediateThinScheduler; | ||
import io.reactivex.internal.schedulers.SchedulerRunnableWrapper; | ||
import io.reactivex.internal.subscriptions.ScalarSubscription; | ||
import io.reactivex.observables.ConnectableObservable; | ||
import io.reactivex.parallel.ParallelFlowable; | ||
import io.reactivex.schedulers.Schedulers; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
|
||
import java.io.IOException; | ||
import java.io.InterruptedIOException; | ||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class RxJavaPluginsTest { | ||
|
||
|
@@ -2255,4 +2265,37 @@ public void isBug() { | |
assertTrue(RxJavaPlugins.isBug(new CompositeException(new TestException()))); | ||
assertTrue(RxJavaPlugins.isBug(new OnErrorNotImplementedException(new TestException()))); | ||
} | ||
|
||
@Test | ||
public void unwrappedTask() { | ||
class TestSchedulerRunnableWrapper implements SchedulerRunnableWrapper { | ||
private final Runnable decoratedRun; | ||
|
||
private TestSchedulerRunnableWrapper(Runnable decoratedRun) { | ||
this.decoratedRun = decoratedRun; | ||
} | ||
|
||
@Override | ||
public Runnable getWrappedRunnable() { | ||
return decoratedRun; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
throw new NullPointerException(); | ||
} | ||
} | ||
|
||
final Runnable runnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
|
||
} | ||
}; | ||
SchedulerRunnableWrapper wrapper = new TestSchedulerRunnableWrapper(runnable); | ||
Runnable unwrappedRunnable = RxJavaPlugins.unwrapRunnable(wrapper); | ||
|
||
assertEquals(runnable, unwrappedRunnable); | ||
unwrappedRunnable.run(); | ||
} | ||
} |
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.
Please make sure your IDE doesn't unroll star imports to reduce the diff size.
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.
ok