/** * Create a {@link ReplayProcessor} that caches the last element it has pushed, * replaying it to late subscribers. This is a buffer-based ReplayProcessor with * a history size of 1. * <p> * <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.3.RELEASE/src/docs/marble/replaylast.png" * alt=""> * * @param <T> the type of the pushed elements * * @return a new {@link ReplayProcessor} that replays its last pushed element to each new * {@link Subscriber} */ public static <T> ReplayProcessor<T> cacheLast() { return cacheLastOrDefault(null); }
@Test public void combineWithOneElement() throws InterruptedException, TimeoutException { AtomicReference<Object> ref = new AtomicReference<>(null); Phaser phaser = new Phaser(2); Flux<Object> s1 = ReplayProcessor.cacheLastOrDefault(new Object()) .publishOn(asyncGroup); Flux<Object> s2 = ReplayProcessor.cacheLastOrDefault(new Object()) .publishOn(asyncGroup); // The following works: //List<Flux<Object>> list = Arrays.collectList(s1); // The following fails: List<Flux<Object>> list = Arrays.asList(s1, s2); Flux.combineLatest(list, t -> t) .log() .doOnNext(obj -> { ref.set(obj); phaser.arrive(); }) .subscribe(); phaser.awaitAdvanceInterruptibly(phaser.arrive(), 1, TimeUnit.SECONDS); Assert.assertNotNull(ref.get()); }
/** * Create a {@link ReplayProcessor} that caches the last element it has pushed, * replaying it to late subscribers. This is a buffer-based ReplayProcessor with * a history size of 1. * <p> * <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.3.RELEASE/src/docs/marble/replaylast.png" * alt=""> * * @param <T> the type of the pushed elements * * @return a new {@link ReplayProcessor} that replays its last pushed element to each new * {@link Subscriber} */ public static <T> ReplayProcessor<T> cacheLast() { return cacheLastOrDefault(null); }