-
-
Save kccheung/08ce87cb82a145d87e33ba2e4d029bfa to your computer and use it in GitHub Desktop.
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
public class WeakSubscriberDecorator<T> extends Subscriber<T> { | |
private final WeakReference<Subscriber<T>> mWeakSubscriber; | |
public WeakSubscriberDecorator(Subscriber<T> subscriber) { | |
this.mWeakSubscriber = new WeakReference<Subscriber<T>>(subscriber); | |
} | |
@Override | |
public void onCompleted() { | |
Subscriber<T> subscriber = mWeakSubscriber.get(); | |
if (subscriber != null) { | |
subscriber.onCompleted(); | |
} | |
} | |
@Override | |
public void onError(Throwable e) { | |
Subscriber<T> subscriber = mWeakSubscriber.get(); | |
if (subscriber != null) { | |
subscriber.onError(e); | |
} | |
} | |
@Override | |
public void onNext(T t) { | |
Subscriber<T> subscriber = mWeakSubscriber.get(); | |
if (subscriber != null) { | |
subscriber.onNext(t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment