Interface Streamable<T>

Type Parameters:
T - the element type of the Streamable sequence.
All Known Subinterfaces:
StreamProcessor<In,Out>
All Known Implementing Classes:
DispatchStreamProcessor, GroupedStreamable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Streamable<@NonNull T>

Represents a virtual-thread capable, multi-valued (a)synchronous sequence of values that builds upon the Java CompletionStage-based concurrency-coordination model.

The lifecycle of the sequence is as follows:

It is always necessary to have the consumer call finish because that is responsible for cleaning up resources of the upstream.

Downstream cancellations are signaled via the StreamerCancellation, where operators can register their own Disposables that get disposed. Because dispose can happen at any time and asynchronously to the consumption loop, the sensitive sources must complete their waiting CompletionStage returned by next exceptionally via a CancellationException. This will unblock the loops and invoke the finish method of the lifecycle at the consumer thread. Depending on the operator, the CancellationException may not be propagated further.

If a source wishes to fail, it must signal the Throwable via the returned CompletionStage of next. If the finish also throws, its Throwable should be added as suppressed exception to the original Throwable.

The Streamer methods must be invoked sequentially and non-overlappingly, similar to the Reactive Streams rule ยง1.3.

This reactive type was modeled after the C# IAsyncEnumerable and IAsyncEnumerator interfaces. Unfortunately, Java never added any async/await infrastructure, plus CompletionStage doesn't even have any native way to blockingly join to it. Therefore, when running in a (virtual) blocking fashion, one may use the Streamer.awaitNext() or Streamer.awaitFinish() helper methods.

Since:
4.0.0