Interface StreamSink<T>
- Type Parameters:
T- the item type to be offered
- All Known Subinterfaces:
StreamProcessor<In,Out>
- All Known Implementing Classes:
DispatchStreamProcessor
public interface StreamSink<@NonNull T>
An interface to submit items and terminal events to a consumer that indacates when the processing of
said item or terminal event has completed, similar to how
Flow.Subscriber can receive events.
The general contract is to call next(Object) zero or more times, then
call finish(Throwable) at most once, all in a non-overlapping fashion and only if the
returned CompletionStage has completed in some fashion.
- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptionReturns theDisposableContainerto use to detect if the consumer has indicated no more items it is willing to accept.static <T> @NonNull StreamSink<T> create(@NonNull Function<? super T, ? extends CompletionStage<Boolean>> onNext, @NonNull Function<? super Throwable, ? extends CompletionStage<Void>> onFinish) Offer the final, terminal event.Offer the next item.default @NonNull StreamSink<T> withCancellation(DisposableStreamerCancellation cancellation) Returns a newStreamSinkthat returns the givenDisposableStreamerCancellationin itscancellation(), allowing overriding the cancellation management of thisStreamSink
-
Method Details
-
next
Offer the next item.- Parameters:
item- the item being offered- Returns:
- a
CompletionStagethat completes withtrueif the value was successfully consumed,falseif the value was rejected or exceptionally on error
-
finish
Offer the final, terminal event.- Parameters:
throwable- the optional throwable to signal error,nullto signal normal completion- Returns:
- a
CompletionStagethat completes withnullif the call succeeded or exceptionally on error
-
cancellation
Returns theDisposableContainerto use to detect if the consumer has indicated no more items it is willing to accept.The default implementation returns a fresh
CompositeDisposable.- Returns:
- the
DisposableContainer
-
withCancellation
@NonNull default @NonNull StreamSink<T> withCancellation(DisposableStreamerCancellation cancellation) Returns a newStreamSinkthat returns the givenDisposableStreamerCancellationin itscancellation(), allowing overriding the cancellation management of thisStreamSink- Parameters:
cancellation- theDisposableStreamerCancellationto use as cancellation management- Returns:
- the new
StreamSinkinstance - Throws:
NullPointerException- ifcancellationisnull
-
create
@NonNull static <T> @NonNull StreamSink<T> create(@NonNull @NonNull Function<? super T, ? extends CompletionStage<Boolean>> onNext, @NonNull @NonNull Function<? super Throwable, ? extends CompletionStage<Void>> onFinish) Creates aStreamSinkvia lambda callbacks fornext(Object)andfinish(Throwable).Non-fatal exceptions thrown by the callbacks are turned into failed
CompletableFuture.failedFuture(Throwable)s.- Type Parameters:
T- the element type of the stream- Parameters:
onNext- the callback for thenextmethodonFinish- the callback for thefinishmethod- Returns:
- the new
StreamSinkinstance
-