1

I have a instace of io.vertx.core.Future, because I need to set multiples handlers into the same Future, according this issue https://github.com/eclipse/vert.x/issues/1920 the way to go is with Observables.

But I found no way to get a Observable from a Future.

I tried rx.Observable.from( Future ) but it does not work because it is not a Java Future.

I look through RxHelper and there is no toObservable method that takes a Future as parameter.

What am I missing? Any help is appreciated.

Fernando
  • 2,131
  • 3
  • 27
  • 46

1 Answers1

1

You can create an ObservableFuture and use its handler as the handler of your original Future

import io.vertx.core.Future
import io.vertx.rx.java.RxHelper

def myFuture = Future.<String> future()

def obsFut = RxHelper.observableFuture()
myFuture.setHandler(obsFut.toHandler())

obsFut.subscribe({ s ->
  println "Hello $s"
})

myFuture.complete("John")

prints

Hello John
tsegismont
  • 8,591
  • 1
  • 17
  • 27