use of rx.Subscriber in project sqlbrite by square.
the class QueryToListOperator method call.
@Override
public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super List<T>> subscriber) {
return new Subscriber<SqlBrite.Query>(subscriber) {
@Override
public void onNext(SqlBrite.Query query) {
try {
Cursor cursor = query.run();
if (cursor == null || subscriber.isUnsubscribed()) {
return;
}
List<T> items = new ArrayList<>(cursor.getCount());
try {
while (cursor.moveToNext()) {
items.add(mapper.call(cursor));
}
} finally {
cursor.close();
}
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(items);
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
onError(OnErrorThrowable.addValueAsLastCause(e, query.toString()));
}
}
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
};
}
use of rx.Subscriber in project sqlbrite by square.
the class QueryToOneOperator method call.
@Override
public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super T> subscriber) {
return new Subscriber<SqlBrite.Query>(subscriber) {
@Override
public void onNext(SqlBrite.Query query) {
try {
boolean emit = false;
T item = null;
Cursor cursor = query.run();
if (cursor != null) {
try {
if (cursor.moveToNext()) {
item = mapper.call(cursor);
emit = true;
if (cursor.moveToNext()) {
throw new IllegalStateException("Cursor returned more than 1 row");
}
}
} finally {
cursor.close();
}
}
if (!subscriber.isUnsubscribed()) {
if (emit) {
subscriber.onNext(item);
} else if (emitDefault) {
subscriber.onNext(defaultValue);
} else {
// Account upstream for the lack of downstream emission.
request(1L);
}
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
onError(OnErrorThrowable.addValueAsLastCause(e, query.toString()));
}
}
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
};
}
use of rx.Subscriber in project Rutgers-Course-Tracker by tevjef.
the class ChooserPresenterImpl method loadSystemMessage.
@Override
public void loadSystemMessage() {
cancePreviousSubscription();
Subscriber<SystemMessage> mSubscriber = new Subscriber<SystemMessage>() {
@Override
public void onCompleted() {
//Noop
}
@Override
public void onError(Throwable e) {
//Noop
}
@Override
public void onNext(SystemMessage systemMessage) {
if (getView() != null) {
getView().showMessage(systemMessage);
}
}
};
mSubsciption = mRetroRutgers.getSystemMessage().doOnSubscribe(new Action0() {
@Override
public void call() {
isLoading = true;
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
isLoading = false;
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
use of rx.Subscriber in project Shuttle by timusus.
the class QueryToListOperator method call.
@Override
public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super List<T>> subscriber) {
return new Subscriber<SqlBrite.Query>(subscriber) {
@Override
public void onNext(SqlBrite.Query query) {
try {
Cursor cursor = query.run();
if (cursor == null) {
return;
}
List<T> items = new ArrayList<>(cursor.getCount());
try {
for (int i = 1; cursor.moveToNext() && !subscriber.isUnsubscribed(); i++) {
T item = mapper.call(cursor);
if (item == null) {
throw new NullPointerException("Mapper returned null for row " + i);
}
items.add(item);
}
} finally {
cursor.close();
}
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(items);
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
onError(OnErrorThrowable.addValueAsLastCause(e, query.toString()));
}
}
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
};
}
use of rx.Subscriber in project Shuttle by timusus.
the class QueryToOneOperator method call.
@Override
public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super T> subscriber) {
return new Subscriber<SqlBrite.Query>(subscriber) {
@Override
public void onNext(SqlBrite.Query query) {
try {
boolean emit = false;
T item = null;
Cursor cursor = query.run();
if (cursor != null) {
try {
if (cursor.moveToNext()) {
item = mapper.call(cursor);
emit = true;
if (cursor.moveToNext()) {
throw new IllegalStateException("Cursor returned more than 1 row");
}
}
} finally {
cursor.close();
}
}
if (!subscriber.isUnsubscribed()) {
if (emit) {
subscriber.onNext(item);
} else if (emitDefault) {
subscriber.onNext(defaultValue);
} else {
// Account upstream for the lack of downstream emission.
request(1L);
}
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
onError(OnErrorThrowable.addValueAsLastCause(e, query.toString()));
}
}
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
};
}
Aggregations