Interface SerialBatch<T>
-
- Type Parameters:
T
- the type of value produced by each promise in the batch
- All Superinterfaces:
Batch<T>
public interface SerialBatch<T> extends Batch<T>
A batch of promises to be processed, serially.Serial batches can be created via
of(java.lang.Iterable<? extends ratpack.exec.Promise<? extends T>>)
.Serial batches are faster than
parallel batches
when the batch size is small and jobs complete quickly.- Since:
- 1.4
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Operation
forEach(BiAction<? super Integer,? super T> consumer)
Processes the promises of the batch, stopping at the first error, emitting results to the given callback.static <T> SerialBatch<T>
of(Iterable<? extends Promise<? extends T>> promises)
Creates a new serial batch of the given promises.static <T> SerialBatch<T>
of(Promise<? extends T>... promises)
Creates a new serial batch of the given promises.TransformablePublisher<T>
publisher()
Creates a publisher that emits the promised values.Promise<List<T>>
yield()
Processes all the promises of the batch, stopping at the first error.Promise<List<? extends ExecResult<T>>>
yieldAll()
Processes all the promises of the batch, collecting any errors.
-
-
-
Method Detail
-
of
static <T> SerialBatch<T> of(Iterable<? extends Promise<? extends T>> promises)
Creates a new serial batch of the given promises.- Type Parameters:
T
- the type of item produced by each promise- Parameters:
promises
- the promises- Returns:
- a
SerialBatch
-
of
@SafeVarargs static <T> SerialBatch<T> of(Promise<? extends T>... promises)
Creates a new serial batch of the given promises.- Type Parameters:
T
- the type of item produced by each promise- Parameters:
promises
- the promises- Returns:
- a
SerialBatch
-
yieldAll
Promise<List<? extends ExecResult<T>>> yieldAll()
Processes all the promises of the batch, collecting any errors.This method differs from
Batch.yield()
in that every promise will be processed, regardless of any failure. As such, it returnsExecResult
objects representing the outcome as it may be an error.The promise returned from this method will not fail, as failure is conveyed via the result objects of the list.
The order of the entries in the promised list corresponds to the order of the promises originally. That is, it is guaranteed that the 2nd item in the list was the 2nd promise specified.
-
yield
Promise<List<T>> yield()
Processes all the promises of the batch, stopping at the first error.This method differs from
Batch.yieldAll()
in that processing will be halted as soon as the first error occurs. The error will be propagated through the returned promise.The order of the entries in the promised list corresponds to the order of the promises originally. That is, it is guaranteed that the 2nd item in the list was the 2nd promise specified. It does not reflect the order in which promises completed.
-
forEach
Operation forEach(BiAction<? super Integer,? super T> consumer)
Processes the promises of the batch, stopping at the first error, emitting results to the given callback.This method is useful for aggregating or reducing the batch.
The returned operation will complete after all items have been consumed or if there is an error.
The integer value given the to consumer indicates the source position of the corresponding promise.
-
publisher
TransformablePublisher<T> publisher()
Creates a publisher that emits the promised values.This method differs to
Batch.yield()
andBatch.yieldAll()
in that items are emitted as soon as they have completed. As such, it is more appropriate when wanting to stream the results in some fashion.Items are emitted in completion order, not source order.
Processing is effectively halted when the first error occurs.
The returned publisher is NOT
execution bound
.
-
-