Class UniHelper

java.lang.Object
io.smallrye.mutiny.vertx.UniHelper

public class UniHelper extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Consumer
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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 io.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.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 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 io.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.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