-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Proposal/rehash: Use async Messaging #416
Changes from 16 commits
49987ee
b9bc520
e1e680f
0a89470
2cbf877
5f29581
da14acf
ac213bb
2e64d32
551b7b4
2d46b26
c9e2bbf
69cffc3
3fa20bb
6750639
81ac21a
d9a51a7
6fbdff3
1c1182b
1fe6366
4ef9c53
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 |
---|---|---|
|
@@ -13,20 +13,21 @@ | |
*/ | ||
package io.reactivex.android.schedulers; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import android.os.Message; | ||
import io.reactivex.Scheduler; | ||
import io.reactivex.android.plugins.RxAndroidPlugins; | ||
import java.util.concurrent.Callable; | ||
|
||
/** Android-specific Schedulers. */ | ||
public final class AndroidSchedulers { | ||
|
||
private static final class MainHolder { | ||
|
||
static final Scheduler DEFAULT = new HandlerScheduler(new Handler(Looper.getMainLooper())); | ||
static final Scheduler DEFAULT | ||
= new HandlerScheduler(new Handler(Looper.getMainLooper()), false); | ||
} | ||
|
||
private static final Scheduler MAIN_THREAD = RxAndroidPlugins.initMainThreadScheduler( | ||
|
@@ -43,8 +44,31 @@ public static Scheduler mainThread() { | |
|
||
/** A {@link Scheduler} which executes actions on {@code looper}. */ | ||
public static Scheduler from(Looper looper) { | ||
return from(looper, false); | ||
} | ||
|
||
/** | ||
* A {@link Scheduler} which executes actions on {@code looper}. | ||
* | ||
* @param async if true, the scheduler will use async messaging on API >= 16 to avoid VSYNC | ||
* locking. On API < 16, this will no-op. | ||
* @see android.os.Message#setAsynchronous(boolean) | ||
*/ | ||
@SuppressLint("NewApi") | ||
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. Is this still needed? 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 guess because the conditional is reversed it is 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. Yeah :/ |
||
public static Scheduler from(Looper looper, boolean async) { | ||
if (looper == null) throw new NullPointerException("looper == null"); | ||
return new HandlerScheduler(new Handler(looper)); | ||
boolean useAsync = async && Build.VERSION.SDK_INT >= 16; | ||
// Confirm the method is there | ||
Handler handler = new Handler(looper); | ||
if (useAsync) { | ||
Message message = Message.obtain(handler); | ||
try { | ||
message.setAsynchronous(true); | ||
} catch (NoSuchMethodError e) { | ||
useAsync = false; | ||
} | ||
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. We should recycle 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. |
||
} | ||
return new HandlerScheduler(new Handler(looper), useAsync); | ||
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. You already created 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. derp, 6fbdff3 |
||
} | ||
|
||
private AndroidSchedulers() { | ||
|
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.
shouldn't need to specify package since this is now imported
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.
4ef9c53