-
Notifications
You must be signed in to change notification settings - Fork 138
Example : Implementing a Quorum
johnmcclean-aol edited this page Jan 24, 2015
·
5 revisions
When operating under SLA's it may be better to return the result of some processing and meet the SLA than wait until all processing is complete and return the full result.
The block method in SimpleReact facilitates this by accepting a Predicate. The Status entity has the following fields available :
int completed; (successfully completed results)
int errors; (completed with errors) (getAllCompleted = completed + eror
int total; (total expected results)
long elapsedNanos; (elapsed time in nanos - also available in millis)
count =0;
List<Integer> result = new SimpleReact()
.<Integer> react(() -> 1, () -> 2, () -> 3)
.then(it -> it * 100)
.then(it -> {
sleep(it);
return it;
}).capture(e -> count++)
.block(status -> status.getAllCompleted() >1 && status.getElapsedMillis()>200);
assertThat(result.size(), is(2));
assertThat(count, is(0));
oops - my bad