use of rx.Scheduler in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsSpecifiedScheduler.
@Test
public void defaultSchedulerReturnsSpecifiedScheduler() {
Scheduler scheduler = mock(Scheduler.class);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).defaultScheduler(scheduler).build();
assertThat(storIOSQLite.defaultScheduler()).isSameAs(scheduler);
}
use of rx.Scheduler in project retrofit by square.
the class RxJavaObserveOnMainThread method main.
public static void main(String... args) {
// Or use mainThread() for Android.
Scheduler observeOn = Schedulers.computation();
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com").addCallAdapterFactory(new ObserveOnMainCallAdapterFactory(observeOn)).addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(io())).build();
// Services created with this instance that use Observable will execute on the 'io' scheduler
// and notify their observer on the 'computation' scheduler.
}
use of rx.Scheduler in project ratpack by ratpack.
the class MultiExecControllerBackedScheduler method getDelegateScheduler.
private Scheduler getDelegateScheduler() {
return ExecController.current().map(c -> map.computeIfAbsent(c, ExecControllerBackedScheduler::new)).orElseGet(() -> {
if (fallback.get() == null) {
int nThreads = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(nThreads);
Scheduler scheduler = Schedulers.from(executor);
fallback.compareAndSet(null, scheduler);
}
return fallback.get();
});
}
use of rx.Scheduler in project grakn by graknlabs.
the class BatchExecutorClient method add.
/**
* Will block until there is space for the query to be submitted
*/
public Observable<QueryResponse> add(Query<?> query, Keyspace keyspace, boolean keepErrors) {
QueryRequest queryRequest = new QueryRequest(query);
queryRequest.acquirePermit();
Context contextAddTimer = addTimer.time();
Observable<QueryResponse> observable = new QueriesObservableCollapser(queryRequest, keyspace).observe().doOnError(error -> failureMeter.mark()).doOnEach(a -> {
if (a.getThrowable() != null) {
LOG.error("Error while executing statement", a.getThrowable());
} else if (a.isOnNext()) {
LOG.trace("Executed {}", a.getValue());
}
}).subscribeOn(scheduler).doOnTerminate(contextAddTimer::close);
return keepErrors ? observable : ignoreErrors(observable);
}
use of rx.Scheduler in project vertx-examples by vert-x3.
the class Scheduled method start.
@Override
public void start() throws Exception {
Observable<String> o = Observable.just("someID1", "someID2", "someID3", "someID4");
// This scheduler can execute blocking actions
Scheduler scheduler = io.vertx.rxjava.core.RxHelper.blockingScheduler(vertx);
// All operations done on the observer now can be blocking
o = o.observeOn(scheduler);
// Load from a blocking api
o = o.map(id -> blockingLoad(id));
o.subscribe(item -> {
System.out.println("Got item " + item);
}, err -> {
err.printStackTrace();
}, () -> {
System.out.println("Done");
});
}
Aggregations