Package io.smallrye.mutiny.vertx
Class UniHelper
java.lang.Object
io.smallrye.mutiny.vertx.UniHelper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> io.vertx.core.Future<T>
toFuture
(io.smallrye.mutiny.Uni<T> single) Adapts anUni<T>
to a Vert.xio.vertx.core.Future<T>
.static <T> io.smallrye.mutiny.subscription.UniSubscriber<T>
toSubscriber
(io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> handler) Adapts an Vert.xHandler<AsyncResult<T>>
to anUniSubscriber
.static <T> io.smallrye.mutiny.Uni<T>
toUni
(io.vertx.core.Future<T> future) static <T> io.smallrye.mutiny.Uni<T>
Returns aUni
that, when subscribed, uses the providedhandler
to adapt a callback-based asynchronous method.
-
Field Details
-
NOOP
-
-
Constructor Details
-
UniHelper
public UniHelper()
-
-
Method Details
-
toUni
public static <T> io.smallrye.mutiny.Uni<T> toUni(Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>> handler) Returns aUni
that, when subscribed, uses the providedhandler
to adapt a callback-based asynchronous method.For example:
{ @code io.vertx.core.Vertx vertx = Vertx.vertx(); Uni
blockingMethodResult = UniHelper .toMaybe(handler -> vertx. executeBlocking(fut -> fut.complete(invokeBlocking()), handler)); } This is useful when using Mutiny without the Vert.x Mutiny API or your own asynchronous methods.
- Parameters:
handler
- the code executed when the returnedUni
is subscribed.- Returns:
- the uni
-
toFuture
public static <T> io.vertx.core.Future<T> toFuture(io.smallrye.mutiny.Uni<T> single) Adapts anUni<T>
to a Vert.xio.vertx.core.Future<T>
.The single will be immediately subscribed and the returned future will be updated with the result of the single.
- Parameters:
single
- the single to adapt- Returns:
- the future
-
toUni
public static <T> io.smallrye.mutiny.Uni<T> toUni(io.vertx.core.Future<T> future) -
toSubscriber
public static <T> io.smallrye.mutiny.subscription.UniSubscriber<T> toSubscriber(io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> handler) Adapts an Vert.xHandler<AsyncResult<T>>
to anUniSubscriber
.The returned observer can be subscribed to an
Uni.subscribe()
.- Parameters:
handler
- the handler to adapt- Returns:
- the observer
-