Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.