Class UniHelper


  • public class UniHelper
    extends Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Consumer NOOP  
    • Constructor Summary

      Constructors 
      Constructor Description
      UniHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> io.vertx.core.Future<T> toFuture​(io.smallrye.mutiny.Uni<T> single)
      Adapts an Uni<T> to a Vert.x Future.
      static <T> io.smallrye.mutiny.subscription.UniSubscriber<T> toSubscriber​(io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> handler)
      Adapts an Vert.x Handler<AsyncResult<T>> to an UniSubscriber.
      static <T> io.smallrye.mutiny.Uni<T> toUni​(io.vertx.core.Future<T> future)  
      static <T> io.smallrye.mutiny.Uni<T> toUni​(Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>> handler)
      Returns a Uni that, when subscribed, uses the provided handler to adapt a callback-based asynchronous method.
    • Constructor Detail

      • UniHelper

        public UniHelper()
    • Method Detail

      • toUni

        public static <T> io.smallrye.mutiny.Uni<T> toUni​(Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>> handler)
        Returns a Uni that, when subscribed, uses the provided handler 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 returned Uni is subscribed.
        Returns:
        the uni
      • toFuture

        public static <T> io.vertx.core.Future<T> toFuture​(io.smallrye.mutiny.Uni<T> single)
        Adapts an Uni<T> to a Vert.x Future.

        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.x Handler<AsyncResult<T>> to an UniSubscriber.

        The returned observer can be subscribed to an Uni.subscribe().

        Parameters:
        handler - the handler to adapt
        Returns:
        the observer