Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it necessary to use #12

Closed
sagar15795 opened this issue Jul 11, 2016 · 2 comments
Closed

Is it necessary to use #12

sagar15795 opened this issue Jul 11, 2016 · 2 comments

Comments

@sagar15795
Copy link

sagar15795 commented Jul 11, 2016

What is the use of this line
if (subscriber.isUnsubscribed()) return;

in below code.

  public Observable<Ribot> setRibots(final Collection<Ribot> newRibots) {
        return Observable.create(new Observable.OnSubscribe<Ribot>() {
            @Override
            public void call(Subscriber<? super Ribot> subscriber) {
                if (subscriber.isUnsubscribed()) return;
                BriteDatabase.Transaction transaction = mDb.newTransaction();
                try {
                    mDb.delete(Db.RibotProfileTable.TABLE_NAME, null);
                    for (Ribot ribot : newRibots) {
                        long result = mDb.insert(Db.RibotProfileTable.TABLE_NAME,
                                Db.RibotProfileTable.toContentValues(ribot.profile()),
                                SQLiteDatabase.CONFLICT_REPLACE);
                        if (result >= 0) subscriber.onNext(ribot);
                    }
                    transaction.markSuccessful();
                    subscriber.onCompleted();
                } finally {
                    transaction.end();
                }
            }
        });
    }

Is it necessary to use it ??

@ivacf
Copy link
Contributor

ivacf commented Jul 12, 2016

Yes, when using Observable.create() you need to check that the subscription is not unsubscribed before doing anything else.

There is better operators than Observable.create() that you can use. See this issue #10 for more info.

@sagar15795
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants