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 aSingleinstance that completes immediately.static <T> Single<T>error(Throwable error)Create aSingleinstance that reports the given given exception to its subscriber(s).static <T> Single<T>from(Flow.Publisher<T> source)Create aSingleinstance that publishes the first and only item received from the given publisher.default Tget()Short-hand fortoFuture().toCompletableFuture().get().default Tget(long timeout, TimeUnit unit)Short-hand fortoFuture().toCompletableFuture().get().static <T> Single<T>just(T item)Create aSingleinstance 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 aSingleinstance that never completes.default CompletionStage<T>toStage()Exposes thisSingleinstance 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 thisSingleinstance as aCompletionStage. Note that if thisSinglecompletes without a value, the resultingCompletionStagewill 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 aSingleinstance that publishes the first and only item received from the given publisher. Note that if the publisher publishes more than one item, the resultingSinglewill 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 aSingleinstance 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 aSingleinstance 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 aSingleinstance that completes immediately.- Type Parameters:
T- item type- Returns:
- Single
-
-