package io.vertx.example.core.future;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.example.util.Runner;

import java.util.function.Function;

/**
 * An example showing how to use {@link io.vertx.core.Future#compose(Function)}
 */
public class ComposeExample extends AbstractVerticle {

  public static void main(String[] args) {
    Runner.runExample(ComposeExample.class);
  }


  @Override
  public void start() throws Exception {
    Future<String> future = anAsyncAction();
    future.compose(this::anotherAsyncAction)
      .setHandler(ar -> {
        if (ar.failed()) {
          System.out.println("Something bad happened");
          ar.cause().printStackTrace();
        } else {
          System.out.println("Result: " + ar.result());
        }
      });
  }

  private Future<String> anAsyncAction() {
    Future<String> future = Future.future();
    // mimic something that take times
    vertx.setTimer(100, l -> future.complete("world"));
    return future;
  }

  private Future<String> anotherAsyncAction(String name) {
    Future<String> future = Future.future();
    // mimic something that take times
    vertx.setTimer(100, l -> future.complete("hello " + name));
    return future;
  }


}

@@ -100,16 +100,46 @@
 Future;%0A
+import io.vertx.core.Promise;%0A
 import i
@@ -872,37 +872,38 @@
 cAction() %7B%0A    
-Futur
+Promis
 e%3CString%3E future
@@ -896,37 +896,40 @@
 String%3E 
-future = Future.futur
+promise = Promise.promis
 e();%0A   
@@ -985,37 +985,38 @@
 Timer(100, l -%3E 
-futur
+promis
 e.complete(%22worl
@@ -1028,30 +1028,40 @@
 %0A    return 
+promise.
 future
+()
 ;%0A  %7D%0A%0A  pri
@@ -1114,29 +1114,30 @@
 name) %7B%0A    
-Futur
+Promis
 e%3CString%3E fu
@@ -1138,29 +1138,32 @@
 ng%3E 
-future = Future.futur
+promise = Promise.promis
 e();
@@ -1231,21 +1231,22 @@
 0, l -%3E 
-futur
+promis
 e.comple
@@ -1278,22 +1278,32 @@
  return 
+promise.
 future
+()
 ;%0A  %7D%0A%0A%0A

fix the future deprecated