Browse Source

Fixed bug where onComplete would throw an error if onError was called before

master
Anthony Restaino 9 years ago
parent
commit
eda498c65f
  1. 7
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  2. 7
      app/src/main/java/acr/browser/lightning/react/Observable.java

7
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -13,6 +13,7 @@ import android.support.annotation.Nullable; @@ -13,6 +13,7 @@ import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -42,6 +43,8 @@ import butterknife.ButterKnife; @@ -42,6 +43,8 @@ import butterknife.ButterKnife;
public class ReadingActivity extends AppCompatActivity {
private static final String TAG = ReadingActivity.class.getSimpleName();
@Bind(R.id.textViewTitle)
TextView mTitle;
@ -197,11 +200,11 @@ public class ReadingActivity extends AppCompatActivity { @@ -197,11 +200,11 @@ public class ReadingActivity extends AppCompatActivity {
subscriber.onNext(new ReaderInfo(result.getTitle(), result.getText()));
} catch (Exception e) {
subscriber.onError(new Throwable("Encountered exception"));
e.printStackTrace();
Log.e(TAG, "Error parsing page", e);
} catch (OutOfMemoryError e) {
System.gc();
subscriber.onError(new Throwable("Out of memory"));
e.printStackTrace();
Log.e(TAG, "Out of memory", e);
}
subscriber.onComplete();
}

7
app/src/main/java/acr/browser/lightning/react/Observable.java

@ -146,6 +146,7 @@ public class Observable<T> { @@ -146,6 +146,7 @@ public class Observable<T> {
@Nullable private volatile OnSubscribe<T> mOnSubscribe;
@NonNull private final Observable<T> mObservable;
private boolean mOnCompleteExecuted = false;
private boolean mOnError = false;
public SubscriberImpl(@NonNull OnSubscribe<T> onSubscribe, @NonNull Observable<T> observable) {
mOnSubscribe = onSubscribe;
@ -160,10 +161,10 @@ public class Observable<T> { @@ -160,10 +161,10 @@ public class Observable<T> {
@Override
public void onComplete() {
OnSubscribe<T> onSubscribe = mOnSubscribe;
if (!mOnCompleteExecuted && onSubscribe != null) {
if (!mOnCompleteExecuted && onSubscribe != null && !mOnError) {
mOnCompleteExecuted = true;
mObservable.executeOnObserverThread(new OnCompleteRunnable<>(onSubscribe));
} else {
} else if (!mOnError) {
Log.e(TAG, "onComplete called more than once");
throw new RuntimeException("onComplete called more than once");
}
@ -181,7 +182,7 @@ public class Observable<T> { @@ -181,7 +182,7 @@ public class Observable<T> {
public void onError(@NonNull final Throwable throwable) {
OnSubscribe<T> onSubscribe = mOnSubscribe;
if (onSubscribe != null) {
mOnCompleteExecuted = true;
mOnError = true;
mObservable.executeOnObserverThread(new OnErrorRunnable<>(onSubscribe, throwable));
}
}

Loading…
Cancel
Save