Interface Streamable<T>
- Type Parameters:
T- the element type of the stream.
public interface Streamable<@NonNull T>
The holographically emergent
IAsyncEnumerable of the Java world.
Runs best with Virtual Threads.
TODO proper docs- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <@NonNull T>
@NonNull Streamable<T> create(@NonNull VirtualGenerator<@NonNull T> generator) Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.static <@NonNull T>
@NonNull Streamable<T> Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.static <@NonNull T>
@NonNull Streamable<T> create(@NonNull VirtualGenerator<@NonNull T> generator, @NonNull ExecutorService executor) Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.static <@NonNull T>
@NonNull Streamable<T> empty()Returns an emptyStreamablethat never produces an item and just completes.default @NonNull CompletionStageDisposable<Void> forEach(@NonNull BiConsumer<? super @NonNull T, ? super Disposable> consumer, @NonNull DisposableContainer canceller, @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> forEach(@NonNull Consumer<? super @NonNull T> consumer, @NonNull DisposableContainer canceller, @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.static <T> @NonNull Streamable<T> fromPublisher(Flow.Publisher<T> source) Convert any Flow.Publisher into a Streamable sequence.static <T> @NonNull Streamable<T> fromPublisher(Flow.Publisher<T> source, @NonNull ExecutorService executor) Convert any Flow.Publisher into a Streamable sequence.static <@NonNull T>
@NonNull Streamable<T> Returns a single-elementStreamablethat produces the constant item and completes.stream()Realizes the stream and returns an interface that let's one consume it.stream(@NonNull DisposableContainer cancellation) Realizes the stream and returns an interface that let's one consume it.default voidsubscribe(Flow.Subscriber<? super @NonNull T> subscriber) Consume thisStreamablevia the given flow-reactive-streams subscriber.default voidsubscribe(Flow.Subscriber<? super @NonNull T> subscriber, @NonNull ExecutorService executor) Consume thisStreamablevia the given flow-reactive-streams subscriber.default @NonNull TestSubscriber<T> test()Creates a newTestSubscriberand subscribes it to thisStreamable.default @NonNull TestSubscriber<T> test(@NonNull ExecutorService executor) Creates a newTestSubscriberand subscribes it to thisStreamable.Converts the streamable into a Flowable representation, running on the default Executors.newVirtualThreadPerTaskExecutor() virtual thread.toFlowable(@NonNull ExecutorService executor) Converts the streamable into a Flowable representation, running on the provided executor service.default <@NonNull R>
@NonNull Streamable<R> Transforms the upstream sequence into zero or more elements for the downstream.default <@NonNull R>
@NonNull Streamable<R> transform(@NonNull VirtualTransformer<@NonNull T, @NonNull R> transformer, @NonNull ExecutorService executor) Transforms the upstream sequence into zero or more elements for the downstream.
-
Method Details
-
stream
@CheckReturnValue @NonNull @NonNull Streamer<T> stream(@NonNull @NonNull DisposableContainer cancellation) Realizes the stream and returns an interface that let's one consume it.- Parameters:
cancellation- where to register and listen for cancellation calls.- Returns:
- the Streamer instance to consume.
-
stream
Realizes the stream and returns an interface that let's one consume it.- Returns:
- the Streamer instance to consume.
-
empty
Returns an emptyStreamablethat never produces an item and just completes.- Type Parameters:
T- the element type- Returns:
- the
Streamableinstance
-
just
@CheckReturnValue @NonNull static <@NonNull T> @NonNull Streamable<T> just(@NonNull @NonNull T item) Returns a single-elementStreamablethat produces the constant item and completes.- Type Parameters:
T- the element type- Parameters:
item- the constant item to produce- Returns:
- the
Streamableinstance
-
fromPublisher
@CheckReturnValue @NonNull static <T> @NonNull Streamable<T> fromPublisher(@NonNull Flow.Publisher<T> source) Convert any Flow.Publisher into a Streamable sequence.- Type Parameters:
T- the element type- Parameters:
source- Flow.Publisher to convert- Returns:
- the new Streamable instance
-
fromPublisher
@CheckReturnValue @NonNull static <T> @NonNull Streamable<T> fromPublisher(@NonNull Flow.Publisher<T> source, @NonNull @NonNull ExecutorService executor) Convert any Flow.Publisher into a Streamable sequence.- Type Parameters:
T- the element type- Parameters:
source- Flow.Publisher to convertexecutor- where the conversion will run- Returns:
- the new Streamable instance
-
create
@CheckReturnValue @NonNull static <@NonNull T> @NonNull Streamable<T> create(@NonNull @NonNull VirtualGenerator<@NonNull T> generator) Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.Runs on the
Schedulers.virtual()scheduler.- Type Parameters:
T- the element type- Parameters:
generator- the generator to use- Returns:
- the streamable instance
-
create
@CheckReturnValue @NonNull static <@NonNull T> @NonNull Streamable<T> create(@NonNull @NonNull VirtualGenerator<@NonNull T> generator, @NonNull @NonNull Scheduler scheduler) Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.Runs on the given scheduler.
- Type Parameters:
T- the element type- Parameters:
generator- the generator to usescheduler- the scheduler to run the virtual generator on- Returns:
- the streamable instance
-
create
@CheckReturnValue @NonNull static <@NonNull T> @NonNull Streamable<T> create(@NonNull @NonNull VirtualGenerator<@NonNull T> generator, @NonNull @NonNull ExecutorService executor) Generate a sequence of values via a virtual generator callback (yielder) which is free to block and is natively backpressured.Runs on the given executor service.
- Type Parameters:
T- the element type- Parameters:
generator- the generator to useexecutor- the executor to run the virtual generator on- Returns:
- the streamable instance
-
toFlowable
Converts the streamable into a Flowable representation, running on the default Executors.newVirtualThreadPerTaskExecutor() virtual thread.- Returns:
- the new Flowable instance
-
toFlowable
@CheckReturnValue @NonNull default @NonNull Flowable<T> toFlowable(@NonNull @NonNull ExecutorService executor) Converts the streamable into a Flowable representation, running on the provided executor service.- Parameters:
executor- the executor to use- Returns:
- the new Flowable instance
-
transform
@CheckReturnValue @NonNull default <@NonNull R> @NonNull Streamable<R> transform(@NonNull @NonNull VirtualTransformer<@NonNull T, @NonNull R> transformer) Transforms the upstream sequence into zero or more elements for the downstream.- Type Parameters:
R- the result element type- Parameters:
transformer- the interface to implement the transforming logic- Returns:
- the new Streamable instance
-
transform
@CheckReturnValue @NonNull default <@NonNull R> @NonNull Streamable<R> transform(@NonNull @NonNull VirtualTransformer<@NonNull T, @NonNull R> transformer, @NonNull @NonNull ExecutorService executor) Transforms the upstream sequence into zero or more elements for the downstream.- Type Parameters:
R- the result element type- Parameters:
transformer- the interface to implement the transforming logicexecutor- where to run the transform and blocking operations- Returns:
- the new Streamable instance
-
forEach
@CheckReturnValue @NonNull default @NonNull CompletionStageDisposable<Void> forEach(@NonNull @NonNull Consumer<? super @NonNull T> consumer) Consumes elements from thisStreamablevia the provided executor service.- Parameters:
consumer- the callback that gets the elements until completion- Returns:
- a Disposable that let's one cancel the sequence asynchronously.
-
forEach
@CheckReturnValue @NonNull default @NonNull CompletionStageDisposable<Void> forEach(@NonNull @NonNull Consumer<? super @NonNull T> consumer, @NonNull @NonNull DisposableContainer canceller) Consumes elements from thisStreamablevia the provided executor service.- Parameters:
consumer- the callback that gets the elements until completioncanceller- the container to trigger cancellation of the sequence- Returns:
- the
CompletionStagethat gets notified when the sequence ends
-
forEach
@CheckReturnValue @NonNull default @NonNull CompletionStageDisposable<Void> forEach(@NonNull @NonNull Consumer<? super @NonNull T> consumer, @NonNull @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.- Parameters:
consumer- the callback that gets the elements until completionexecutor- the service that hosts the blocking waits.- Returns:
- a Disposable that let's one cancel the sequence asynchronously.
-
forEach
@CheckReturnValue @NonNull default @NonNull CompletionStageDisposable<Void> forEach(@NonNull @NonNull Consumer<? super @NonNull T> consumer, @NonNull @NonNull DisposableContainer canceller, @NonNull @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.- Parameters:
consumer- the callback that gets the elements until completioncanceller- the container to trigger cancellation of the sequenceexecutor- the service that hosts the blocking waits.- Returns:
- the
CompletionStagethat gets notified when the sequence ends
-
forEach
@CheckReturnValue @NonNull default @NonNull CompletionStageDisposable<Void> forEach(@NonNull @NonNull BiConsumer<? super @NonNull T, ? super Disposable> consumer, @NonNull @NonNull DisposableContainer canceller, @NonNull @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.- Parameters:
consumer- the callback that gets the elements until completioncanceller- the container to trigger cancellation of the sequenceexecutor- the service that hosts the blocking waits.- Returns:
- the
CompletionStagethat gets notified when the sequence ends
-
subscribe
default void subscribe(@NonNull Flow.Subscriber<? super @NonNull T> subscriber, @NonNull @NonNull ExecutorService executor) Consume thisStreamablevia the given flow-reactive-streams subscriber.- Parameters:
subscriber- the subscriber to consume with.executor- the service that hosts the blocking waits.
-
subscribe
Consume thisStreamablevia the given flow-reactive-streams subscriber.- Parameters:
subscriber- the subscriber to consume with.
-
test
Creates a newTestSubscriberand subscribes it to thisStreamable.- Returns:
- the created test subscriber
-
test
@CheckReturnValue @NonNull default @NonNull TestSubscriber<T> test(@NonNull @NonNull ExecutorService executor) Creates a newTestSubscriberand subscribes it to thisStreamable.- Parameters:
executor- the executor to use- Returns:
- the created test subscriber
-