public class BarrierStream extends Stream<List<Object>>
BarrierStream
provides a type of Stream
into which you can bind Consumers
and Functions
from arbitrary components. This allows you to create a Stream
that will be triggered when all bound callbacks have been invoked. The List<Object>
passed
downstream will be the accumulation of all the values either passed into a Consumer
or the return value from
a bound Function
. This provides a way for the user to cleanly create a dependency chain of arbitrary
callbacks and aggregate the results into a single value.
BarrierStream barrierStream = new BarrierStream();
EventBus bus = EventBus.create(Environment.get());
bus.on($("hello"), barrierStream.wrap((Event ev) -> {
System.out.println("got in bus: " + ev.getData());
}));
Streams.just("Hello World!")
.map(barrierStream.wrap((Function) String::toUpperCase))
.consume(s -> {
System.out.println("got in stream: " + s);
});
barrierStream.consume(vals -> {
System.out.println("got vals: " + vals);
});
bus.notify("hello", Event.wrap("Hello World!"));
NOTE: To get blocking semantics for the calling thread, you only need to call Stream.next()
to return a
Promise
.
Constructor and Description |
---|
BarrierStream() |
BarrierStream(Dispatcher dispatcher) |
BarrierStream(Environment env) |
BarrierStream(Environment env,
Dispatcher dispatcher) |
Modifier and Type | Method and Description |
---|---|
void |
subscribe(org.reactivestreams.Subscriber<? super List<Object>> s) |
<I> Consumer<I> |
wrap(Consumer<I> consumer) |
<I,O> Function<I,O> |
wrap(Function<I,O> fn) |
adaptiveConsume, adaptiveConsumeOn, after, batchConsume, batchConsumeOn, broadcast, broadcastOn, broadcastTo, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, cache, cancelSubscription, capacity, cast, combine, concatMap, concatWith, consume, consume, consume, consume, consume, consumeLater, consumeOn, consumeOn, consumeOn, count, count, decode, defaultIfEmpty, dematerialize, dispatchOn, dispatchOn, dispatchOn, distinct, distinct, distinctUntilChanged, distinctUntilChanged, downstreamSubscription, elapsed, elementAt, elementAtOrDefault, encode, env, exists, fanIn, filter, filter, finallyDo, flatMap, getCapacity, getDispatcher, getEnvironment, getTimer, groupBy, ignoreError, ignoreError, isReactivePull, join, joinWith, keepAlive, last, lift, log, log, map, materialize, merge, mergeWith, nest, next, observe, observeCancel, observeComplete, observeError, observeStart, observeSubscribe, onErrorResumeNext, onErrorResumeNext, onErrorReturn, onErrorReturn, onOverflowBuffer, onOverflowBuffer, onOverflowDrop, partition, partition, process, recover, reduce, reduce, repeat, repeat, repeatWhen, requestWhen, retry, retry, retry, retry, retryWhen, sample, sample, sample, sample, sample, sample, sampleFirst, sampleFirst, sampleFirst, sampleFirst, sampleFirst, sampleFirst, scan, scan, skip, skip, skip, skipWhile, skipWhile, sort, sort, sort, sort, split, split, startWith, startWith, startWith, subscribe, subscribeOn, subscribeOn, subscribeOn, switchMap, take, take, take, takeWhile, tap, throttle, throttle, timeout, timeout, timeout, timeout, timestamp, toBlockingQueue, toBlockingQueue, toList, toList, toString, unbounded, when, window, window, window, window, window, window, window, window, window, window, window, zip, zipWith, zipWith
public BarrierStream()
public BarrierStream(Environment env)
public BarrierStream(Dispatcher dispatcher)
public BarrierStream(Environment env, Dispatcher dispatcher)
Copyright © 2016. All rights reserved.