public class ReactCollector<U>
extends java.lang.Object
| Constructor and Description |
|---|
ReactCollector() |
| Modifier and Type | Method and Description |
|---|---|
StageWithResults<java.util.List<U>,U> |
block()
React and block
List<String> strings = SimpleReact.<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> it * 100)
.then((it) -> "*" + it)
.block();
In this example, once the current thread of execution meets the React
block method, it will block until all tasks have been completed. |
<X> StageWithResults<X,U> |
block(java.util.stream.Collector collector) |
<X> StageWithResults<X,U> |
block(java.util.stream.Collector collector,
java.util.function.Predicate<Status> breakout) |
StageWithResults<java.util.List<U>,U> |
block(java.util.function.Predicate<Status> breakout)
React and block with breakout
Sometimes you may not need to block until all the work is complete, one
result or a subset may be enough.
|
<X> StageWithResults<X,U> |
blockAndExtract(Extractor extractor)
Block until tasks complete and return a value determined by the extractor supplied.
|
<X> StageWithResults<X,U> |
blockAndExtract(Extractor extractor,
java.util.function.Predicate<Status> breakout)
Block until tasks complete, or breakout conditions met and return a value determined by the extractor supplied.
|
StageWithResults<U,U> |
first()
Block until first result recieved
|
StageWithResults<U,U> |
last()
Block until all results recieved.
|
public StageWithResults<java.util.List<U>,U> block()
List<String> strings = SimpleReact.<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> it * 100)
.then((it) -> "*" + it)
.block();
In this example, once the current thread of execution meets the React
block method, it will block until all tasks have been completed. The
result will be returned as a List. The Reactive tasks triggered by the
Suppliers are non-blocking, and are not impacted by the block method
until they are complete. Block, only blocks the current thread.public <X> StageWithResults<X,U> block(java.util.stream.Collector collector)
collector - to perform aggregation / reduction operation on the results (e.g. to Collect into a List or String)public StageWithResults<U,U> first()
public StageWithResults<U,U> last()
public <X> StageWithResults<X,U> blockAndExtract(Extractor extractor)
extractor - used to determine which value should be returned, recieves current collected input and extracts a return valuepublic <X> StageWithResults<X,U> blockAndExtract(Extractor extractor, java.util.function.Predicate<Status> breakout)
extractor - used to determine which value should be returned, recieves current collected input and extracts a return valuebreakout - Predicate that determines whether the block should be
continued or removedpublic StageWithResults<java.util.List<U>,U> block(java.util.function.Predicate<Status> breakout)
List<String> strings = SimpleReact.<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then(it -> it * 100)
.then(it -> "*" + it)
.block(status -> status.getCompleted()>1);
In this example the current thread will unblock once more than one result
has been returned.breakout - Predicate that determines whether the block should be
continued or removedpublic <X> StageWithResults<X,U> block(java.util.stream.Collector collector, java.util.function.Predicate<Status> breakout)
collector - to perform aggregation / reduction operation on the results (e.g. to Collect into a List or String)breakout - Predicate that determines whether the block should be
continued or removed