use of io.reactivex.Flowable in project vertx-examples by vert-x3.
the class Scheduled method start.
@Override
public void start() throws Exception {
Flowable<String> o = Flowable.just("someID1", "someID2", "someID3", "someID4");
// This scheduler can execute blocking actions
Scheduler scheduler = io.vertx.reactivex.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");
});
}
use of io.reactivex.Flowable in project cyclops by aol.
the class RxTest method asyncFlowableList2.
@Test
public void asyncFlowableList2() {
AtomicBoolean complete = new AtomicBoolean(false);
Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
Thread.sleep(100);
return i;
}).doOnComplete(() -> complete.set(true));
System.out.println("Initializing!");
ListX<Integer> asyncList = FlowableCollections.listX(async).map(i -> i + 1);
System.out.println("Blocked? " + complete.get());
System.out.println("First value is " + asyncList.get(0));
System.out.println("Blocked? " + complete.get());
}
use of io.reactivex.Flowable in project cyclops by aol.
the class RxTest method asyncFlowableList.
@Test
public void asyncFlowableList() {
AtomicBoolean complete = new AtomicBoolean(false);
Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
Thread.sleep(5000);
return i;
}).doOnComplete(() -> complete.set(true));
ListX<Integer> asyncList = ListX.listX(FlowableReactiveSeq.reactiveSeq(async)).map(i -> i + 1);
System.out.println("Calling materialize!");
asyncList.materialize();
System.out.println("Blocked? " + complete.get());
System.out.println("First value is " + asyncList.get(0));
System.out.println("Blocked? " + complete.get());
}
use of io.reactivex.Flowable in project jersey by jersey.
the class FlowableAgentResource method recommended.
private Flowable<List<Recommendation>> recommended(final Queue<String> errors) {
destination.register(RxFlowableInvokerProvider.class);
// Recommended places.
final Flowable<Destination> recommended = destination.path("recommended").request().header("Rx-User", "RxJava2").rx(RxFlowableInvoker.class).get(new GenericType<List<Destination>>() {
}).onErrorReturn(throwable -> {
errors.offer("Recommended: " + throwable.getMessage());
return Collections.emptyList();
}).flatMap(Flowable::fromIterable).cache();
forecast.register(RxFlowableInvokerProvider.class);
// Forecasts. (depend on recommended destinations)
final Flowable<Forecast> forecasts = recommended.flatMap(destination -> forecast.resolveTemplate("destination", destination.getDestination()).request().rx(RxFlowableInvoker.class).get(Forecast.class).onErrorReturn(throwable -> {
errors.offer("Forecast: " + throwable.getMessage());
return new Forecast(destination.getDestination(), "N/A");
}));
calculation.register(RxFlowableInvokerProvider.class);
// Calculations. (depend on recommended destinations)
final Flowable<Calculation> calculations = recommended.flatMap(destination -> {
return calculation.resolveTemplate("from", "Moon").resolveTemplate("to", destination.getDestination()).request().rx(RxFlowableInvoker.class).get(Calculation.class).onErrorReturn(throwable -> {
errors.offer("Calculation: " + throwable.getMessage());
return new Calculation("Moon", destination.getDestination(), -1);
});
});
return Flowable.zip(recommended, forecasts, calculations, Recommendation::new).buffer(Integer.MAX_VALUE);
}
use of io.reactivex.Flowable in project jersey by jersey.
the class FlowableAgentResource method flowable.
@GET
public void flowable(@Suspended final AsyncResponse async) {
final long time = System.nanoTime();
final Queue<String> errors = new ConcurrentLinkedQueue<>();
Flowable.just(new AgentResponse()).zipWith(visited(errors), (agentResponse, visited) -> {
agentResponse.setVisited(visited);
return agentResponse;
}).zipWith(recommended(errors), (agentResponse, recommendations) -> {
agentResponse.setRecommended(recommendations);
return agentResponse;
}).observeOn(Schedulers.io()).subscribe(agentResponse -> {
agentResponse.setProcessingTime((System.nanoTime() - time) / 1000000);
async.resume(agentResponse);
}, async::resume);
}
Aggregations