-
Notifications
You must be signed in to change notification settings - Fork 206
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
Update to RxJava2 #239
Update to RxJava2 #239
Changes from 2 commits
c3d1b9b
6499f5e
0aa9470
719b297
34f2460
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 |
---|---|---|
@@ -1,33 +1,36 @@ | ||
package com.artemzin.qualitymatters.other; | ||
|
||
import android.support.annotation.NonNull; | ||
import io.reactivex.disposables.Disposable; | ||
import io.reactivex.functions.Action; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import rx.Subscription; | ||
import rx.functions.Action0; | ||
|
||
public class DisposableSubscription implements Subscription { | ||
public class DisposableSubscription implements Disposable { | ||
|
||
@NonNull | ||
private final AtomicBoolean unsubscribed = new AtomicBoolean(false); | ||
private final AtomicBoolean disposed = new AtomicBoolean(false); | ||
|
||
@NonNull | ||
private final Action0 disposeAction; | ||
private final Action disposeAction; | ||
|
||
public DisposableSubscription(@NonNull Action0 disposeAction) { | ||
public DisposableSubscription(@NonNull Action disposeAction) { | ||
this.disposeAction = disposeAction; | ||
} | ||
|
||
@Override | ||
public boolean isUnsubscribed() { | ||
return unsubscribed.get(); | ||
public void dispose() { | ||
if (disposed.compareAndSet(false, true)) { | ||
try { | ||
disposeAction.run(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); // RxJava2 Action throws an exception. Pass it on | ||
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. Should we rethrow here or use the RxJavaPlugins? 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 check out the updated implementation which converts |
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void unsubscribe() { | ||
if (unsubscribed.compareAndSet(false, true)) { | ||
disposeAction.call(); | ||
} | ||
public boolean isDisposed() { | ||
return disposed.get(); | ||
} | ||
} |
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.
I feel like this could be solved with
Disposables.from
instead