@Override public Observable<MarkedEdge> compactNode( final Id inputNode ) { final UUID startTime = UUIDGenerator.newTimeUUID(); final Observable<MarkedEdge> nodeObservable = Observable.just( inputNode ) .map( node -> nodeSerialization.getMaxVersion( scope, node ) ) //.doOnNext(maxTimestamp -> logger.info("compactNode maxTimestamp={}", maxTimestamp.toString())) .takeWhile(maxTimestamp -> maxTimestamp.isPresent() ) //map our delete listener .flatMap( timestamp -> nodeDeleteListener.receive( scope, inputNode, startTime ) ); return ObservableTimer.time( nodeObservable, this.deleteNodeTimer ); }
.takeWhile(new Func1<List<Image>, Boolean>() { @Override public Boolean call(List<Image> images) {
entityEventObservable.takeWhile(writeEvent -> !tracker.shouldStopProcessingEntities()).skip(entityNumSkip) .flatMap(writeEvent -> { return Observable.just(writeEvent).doOnNext(doWork); final int connectionCount = otherEventObservable.takeWhile( writeEvent -> !tracker.shouldStopProcessingConnections()).skip(connectionNumSkip).flatMap(entityWrapper -> { return Observable.just(entityWrapper).doOnNext(doWork).subscribeOn(Schedulers.io());
@Override public void run() { Observable.range(1, 10).takeWhile(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer i) { return i < 3; } }).subscribe(new Action1<Integer>() { @Override public void call(Integer integer) { log(integer); } }); } });
@Override public Observable<Out> call() { Mutable<State> state = new Mutable<State>(initialState.call()); return source.materialize() // do state transitions and emit notifications // use flatMap to emit notification values .flatMap(execute(transition, completion, state, backpressureStrategy), initialRequest) // complete if we encounter an unsubscribed sentinel .takeWhile(NOT_UNSUBSCRIBED) // flatten notifications to a stream which will enable // early termination from the state machine if desired .dematerialize(); } });
@Override public Observable<Out> call() { Mutable<State> state = new Mutable<State>(initialState.call()); return source.materialize() // do state transitions and emit notifications // use flatMap to emit notification values .flatMap(execute(transition, completion, state, backpressureStrategy), initialRequest) // complete if we encounter an unsubscribed sentinel .takeWhile(NOT_UNSUBSCRIBED) // flatten notifications to a stream which will enable // early termination from the state machine if desired .dematerialize(); } });
Observable .interval(1, TimeUnit.SECONDS) .takeWhile(new Func1<Long, Boolean>() { @Override public Boolean call(Long aLong) {
Observable .interval(1, TimeUnit.SECONDS) .takeWhile(new Func1<Long, Boolean>() { @Override public Boolean call(Long aLong) {
void allPeople() { Observable<Person> allPages = Observable .range(0, Integer.MAX_VALUE) .map(this::listPeople) .takeWhile(list -> !list.isEmpty()) .concatMap(Observable::from); }
@Test public void sample_537() throws Exception { Observable.range(1, 5).takeUntil(x -> x == 3); // [1, 2, 3] Observable.range(1, 5).takeWhile(x -> x != 3); // [1, 2] }
/** * Get the shopping cart for a certain user. * * @param userId user id * @return async result */ private Future<ShoppingCart> aggregateCartEvents(String userId) { Future<ShoppingCart> future = Future.future(); // aggregate cart events into raw shopping cart repository.streamByUser(userId) .takeWhile(cartEvent -> !CartEvent.isTerminal(cartEvent.getCartEventType())) .reduce(new ShoppingCart(), ShoppingCart::incorporate) .toSingle() .subscribe(future::complete, future::fail); return future.compose(cart -> getProductService() .compose(service -> prepareProduct(service, cart)) // prepare product data .compose(productList -> generateCurrentCartFromStream(cart, productList)) // prepare product items ); }