Search in sources :

Example 1 with RxResult

use of io.requery.rx.RxResult in project requery by requery.

the class RxTest method testQuerySelfObservableMap.

@Test
public void testQuerySelfObservableMap() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    Subscription subscription = data.select(Person.class).limit(2).get().toSelfObservable().flatMap(new Func1<RxResult<Person>, Observable<Person>>() {

        @Override
        public Observable<Person> call(RxResult<Person> persons) {
            return persons.toObservable();
        }
    }).subscribe(new Action1<Person>() {

        @Override
        public void call(Person persons) {
            count.incrementAndGet();
        }
    });
    data.insert(randomPerson()).toBlocking().value();
    data.insert(randomPerson()).toBlocking().value();
    assertEquals(3, count.get());
    subscription.unsubscribe();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(rx.Subscription) Func1(rx.functions.Func1) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Test(org.junit.Test)

Aggregations

RxResult (io.requery.rx.RxResult)1 Person (io.requery.test.model.Person)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 Subscription (rx.Subscription)1 Func1 (rx.functions.Func1)1