Search in sources :

Example 1 with ReactiveResult

use of io.requery.reactivex.ReactiveResult in project requery by requery.

the class ReactiveTest method testQuerySelfObservableMap.

@Test
public void testQuerySelfObservableMap() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    Disposable disposable = data.select(Person.class).limit(2).get().observableResult().flatMap(new Function<ReactiveResult<Person>, Observable<Person>>() {

        @Override
        public Observable<Person> apply(ReactiveResult<Person> persons) {
            return persons.observable();
        }
    }).subscribe(new Consumer<Person>() {

        @Override
        public void accept(Person persons) {
            count.incrementAndGet();
        }
    });
    data.insert(randomPerson()).blockingGet();
    data.insert(randomPerson()).blockingGet();
    assertEquals(3, count.get());
    disposable.dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Person(io.requery.test.model.Person) ReactiveResult(io.requery.reactivex.ReactiveResult) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 ReactiveResult (io.requery.reactivex.ReactiveResult)1 Person (io.requery.test.model.Person)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1