Last active
November 27, 2016 09:09
-
-
Save kmdupr33/b5fe4b2a67a3473e20c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Can you show an example about how to use it ? 👍