Created
March 14, 2017 11:02
-
-
Save mox601/964e2e7d9110f9f81f2265d75f74c3ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void throttlingRxJava() throws Exception { | |
Observable<Long> everySecond = Observable.fromIterable(Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)) | |
.map(aLong -> { | |
try { | |
Thread.sleep(1_000L); | |
} catch (InterruptedException e) { | |
// | |
} | |
return aLong; | |
}); | |
Observable<Long> everyHundredMillis = Observable.interval(1, TimeUnit.MILLISECONDS); | |
everyHundredMillis | |
.map(a -> System.nanoTime()) | |
.zipWith(everySecond, new BiFunction<Long, Long, Tuple2<Long, Long>>() { | |
@Override | |
public Tuple2<Long, Long> apply(Long aLong, Long aLong2) throws Exception { | |
return Tuples.of(aLong, aLong2); | |
} | |
}) | |
.subscribe(aLong -> log.info(aLong + "")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment