RxAndroid and Kotlin (Part 1)
Ahmed Rizwan
1.5K16

Observable.create is not recommended to use. as your own example states

//Java
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(final Subscriber<? super Integer>
subscriber) {
for (int i = 1; i <= 5; i++)
subscriber.onNext(i);

subscriber.onCompleted();
}
});

and it should be

//Java
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(final Subscriber<? super Integer>
subscriber) { if(!subscriber.isUnsubscribed) { for (int i = 1; i <= 5; i++)
subscriber.onNext(i);

subscriber.onCompleted();} }
});

keep in mind that this can be a source of lot of headache. And if you use .create please remember to add check for subscriber

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.