Skip to content

Instantly share code, notes, and snippets.

@kmdupr33
Created March 24, 2015 23:36
Show Gist options
  • Save kmdupr33/057612a1d383cc196c9a to your computer and use it in GitHub Desktop.
Save kmdupr33/057612a1d383cc196c9a to your computer and use it in GitHub Desktop.
public class SafeObservable<T> extends Observable<T> {
/**
* Creates an Observable with a Function to execute when it is subscribed to.
* <p/>
* <em>Note:</em> Use {@link #create(rx.Observable.OnSubscribe)} to create an Observable, instead of this constructor,
* unless you specifically have a need for inheritance.
*
* @param f {@link rx.Observable.OnSubscribe} to be executed when {@link #subscribe(Subscriber)} is called
*/
protected SafeObservable(OnSubscribe<T> f) {
super(f);
}
public Subscription safeSubscribe(Subscriber<T> subscriber) {
WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
return subscribe(weakSubscriberDecorator);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment