-
public interface ZeroPublisher
Factory methods to simplify the creation of reactive streams compliantFlow.Publisher
.There are convenience methods for creating
Flow.Publisher
from in-memory data.The general-purpose abstraction is to use a
Tube
and thecreate(TubeConfiguration, Consumer)
factory method.
-
-
Method Summary
Static Methods Modifier and Type Method Description static <T> java.util.concurrent.Flow.Publisher<T>
create(TubeConfiguration configuration, java.util.function.Consumer<Tube<T>> tubeConsumer)
Create a newFlow.Publisher
with the general-purposeTube
API.static <T> java.util.concurrent.Flow.Publisher<T>
empty()
Create an emptyFlow.Publisher
that completes upon subscription without ever sending any item.static <T> java.util.concurrent.Flow.Publisher<T>
fromCompletionStage(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier)
Create aFlow.Publisher
from aCompletionStage
.static <T> java.util.concurrent.Flow.Publisher<T>
fromFailure(java.lang.Throwable failure)
Create aFlow.Publisher
from a known failure.static <S,T>
java.util.concurrent.Flow.Publisher<T>fromGenerator(java.util.function.Supplier<S> stateSupplier, java.util.function.Function<S,java.util.Iterator<T>> generator)
Create aFlow.Publisher
from a generator over some state.static <T> java.util.concurrent.Flow.Publisher<T>
fromItems(T... items)
Create aFlow.Publisher
from existing items.static <T> java.util.concurrent.Flow.Publisher<T>
fromIterable(java.lang.Iterable<T> iterable)
Create aFlow.Publisher
from an iterable object.static <T> java.util.concurrent.Flow.Publisher<T>
fromStream(java.util.function.Supplier<java.util.stream.Stream<T>> supplier)
Create aFlow.Publisher
from aStream
.static <T> java.util.concurrent.CompletionStage<java.util.Optional<T>>
toCompletionStage(java.util.concurrent.Flow.Publisher<T> publisher)
Create aCompletionStage
from aFlow.Publisher
.
-
-
-
Method Detail
-
fromItems
@SafeVarargs static <T> java.util.concurrent.Flow.Publisher<T> fromItems(T... items)
Create aFlow.Publisher
from existing items.- Type Parameters:
T
- the items type- Parameters:
items
- the existing items, cannot be anull array
- Returns:
- a new
Flow.Publisher
-
fromIterable
static <T> java.util.concurrent.Flow.Publisher<T> fromIterable(java.lang.Iterable<T> iterable)
Create aFlow.Publisher
from an iterable object.Note that this assumes an in-memory, non-blocking
Iterator
. Do not try to force an iterator as a way to bridge an API withFlow.Publisher
as it does not behave like an in-memory data structure.- Type Parameters:
T
- the items type- Parameters:
iterable
- the iterable object, cannot benull
- Returns:
- a nes
Flow.Publisher
-
fromStream
static <T> java.util.concurrent.Flow.Publisher<T> fromStream(java.util.function.Supplier<java.util.stream.Stream<T>> supplier)
Create aFlow.Publisher
from aStream
.Note that this assumes an in-memory, non-blocking data structure, just like
fromIterable(Iterable)
. Also note that aStream
can only be traversed once, hence the use of a supplier because multiple subscriptions would fail.- Type Parameters:
T
- the items type- Parameters:
supplier
- the stream supplier, cannot benull
- Returns:
- a new
Flow.Publisher
-
fromGenerator
static <S,T> java.util.concurrent.Flow.Publisher<T> fromGenerator(java.util.function.Supplier<S> stateSupplier, java.util.function.Function<S,java.util.Iterator<T>> generator)
Create aFlow.Publisher
from a generator over some state.Note that this assumes an in-memory, non-blocking data structure, just like
fromIterable(Iterable)
.- Type Parameters:
S
- the initial state typeT
- the items type- Parameters:
stateSupplier
- the initial state supplier, cannot benull
but can supplynull
generator
- a generator function over the initial state and an iterator, cannot benull
, cannot yieldnull
- Returns:
- a new
Flow.Publisher
-
fromCompletionStage
static <T> java.util.concurrent.Flow.Publisher<T> fromCompletionStage(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier)
Create aFlow.Publisher
from aCompletionStage
.- Type Parameters:
T
- the item type- Parameters:
completionStageSupplier
- the completion stage supplier, cannot benull
, cannot yieldnull
- Returns:
- a new
Flow.Publisher
-
toCompletionStage
static <T> java.util.concurrent.CompletionStage<java.util.Optional<T>> toCompletionStage(java.util.concurrent.Flow.Publisher<T> publisher)
Create aCompletionStage
from aFlow.Publisher
.The
Flow.Publisher
is requested exactly 1 element and the subscription is cancelled after it has been received.- Type Parameters:
T
- the item type- Parameters:
publisher
- the publisher, cannot benull
- Returns:
- a new
CompletionStage
-
fromFailure
static <T> java.util.concurrent.Flow.Publisher<T> fromFailure(java.lang.Throwable failure)
Create aFlow.Publisher
from a known failure.- Type Parameters:
T
- the items type- Parameters:
failure
- the failure, cannot benull
- Returns:
- a new
Flow.Publisher
-
empty
static <T> java.util.concurrent.Flow.Publisher<T> empty()
Create an emptyFlow.Publisher
that completes upon subscription without ever sending any item.- Type Parameters:
T
- the items type- Returns:
- a new
Flow.Publisher
-
create
static <T> java.util.concurrent.Flow.Publisher<T> create(TubeConfiguration configuration, java.util.function.Consumer<Tube<T>> tubeConsumer)
Create a newFlow.Publisher
with the general-purposeTube
API.- Type Parameters:
T
- the items type- Parameters:
configuration
- the tube configurationtubeConsumer
- the tube consumer, cannot benull
- Returns:
- a new
Flow.Publisher
-
-