Package io.helidon.common.reactive
Interface Single<T>
-
- Type Parameters:
T
- item type
- All Superinterfaces:
Flow.Publisher<T>
,Subscribable<T>
public interface Single<T> extends Subscribable<T>
Single item publisher utility.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <T> Single<T>
empty()
Get aSingle
instance that completes immediately.static <T> Single<T>
error(Throwable error)
Create aSingle
instance that reports the given given exception to its subscriber(s).static <T> Single<T>
from(Flow.Publisher<T> source)
Create aSingle
instance that publishes the first and only item received from the given publisher.default T
get()
Short-hand fortoFuture().toCompletableFuture().get()
.default T
get(long timeout, TimeUnit unit)
Short-hand fortoFuture().toCompletableFuture().get()
.static <T> Single<T>
just(T item)
Create aSingle
instance that publishes the given item to its subscriber(s).default <U> Single<U>
map(Mapper<T,U> mapper)
default <U> Multi<U>
mapMany(Mapper<T,Flow.Publisher<U>> mapper)
static <T> Single<T>
never()
Get aSingle
instance that never completes.default CompletionStage<T>
toStage()
Exposes thisSingle
instance as aCompletionStage
.-
Methods inherited from interface io.helidon.common.reactive.Flow.Publisher
subscribe
-
Methods inherited from interface io.helidon.common.reactive.Subscribable
subscribe, subscribe, subscribe, subscribe
-
-
-
-
Method Detail
-
map
default <U> Single<U> map(Mapper<T,U> mapper)
- Type Parameters:
U
- mapped item type- Parameters:
mapper
- mapper- Returns:
- Single
- Throws:
NullPointerException
- if mapper isnull
-
mapMany
default <U> Multi<U> mapMany(Mapper<T,Flow.Publisher<U>> mapper)
- Type Parameters:
U
- mapped items type- Parameters:
mapper
- mapper- Returns:
- Publisher
- Throws:
NullPointerException
- if mapper isnull
-
toStage
default CompletionStage<T> toStage()
Exposes thisSingle
instance as aCompletionStage
. Note that if thisSingle
completes without a value, the resultingCompletionStage
will be completed exceptionally with anIllegalStateException
- Returns:
- CompletionStage
-
get
default T get() throws InterruptedException, ExecutionException
Short-hand fortoFuture().toCompletableFuture().get()
.- Returns:
- T
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the future completed exceptionally
-
get
default T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Short-hand fortoFuture().toCompletableFuture().get()
.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- T
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the future completed exceptionallyTimeoutException
- if the wait timed out
-
from
static <T> Single<T> from(Flow.Publisher<T> source)
Create aSingle
instance that publishes the first and only item received from the given publisher. Note that if the publisher publishes more than one item, the resultingSingle
will hold an error. UseMulti.first()
instead in order to get the first item of a publisher that may publish more than one item.- Type Parameters:
T
- item type- Parameters:
source
- source publisher- Returns:
- Single
- Throws:
NullPointerException
- if source isnull
-
just
static <T> Single<T> just(T item)
Create aSingle
instance that publishes the given item to its subscriber(s).- Type Parameters:
T
- item type- Parameters:
item
- item to publish- Returns:
- Single
- Throws:
NullPointerException
- if item isnull
-
error
static <T> Single<T> error(Throwable error)
Create aSingle
instance that reports the given given exception to its subscriber(s). The exception is reported by invokingFlow.Subscriber.onError(java.lang.Throwable)
whenFlow.Publisher.subscribe(Subscriber)
is called.- Type Parameters:
T
- item type- Parameters:
error
- exception to hold- Returns:
- Single
- Throws:
NullPointerException
- if error isnull
-
empty
static <T> Single<T> empty()
Get aSingle
instance that completes immediately.- Type Parameters:
T
- item type- Returns:
- Single
-
-