I have a logic where I need to save data in two tables(one-to-many). I have created two methods in my Java and I am trying to using Vertx Future with compose to implement the logic in sequence. But I have got half way and don't understand how to implement the compose when the first future is done. I mean code runs for the first future anAsyncAction_1(materialToAdd);, and the record is saved in the DB but now how do I call my second method in the compose
public Future<Void> anAsyncAction_2(final SendToCompanyFromSupplier rawmaterialToAdd, Integer id)
{
//code to get the id from the first future and save data in the table
}
Below is my code
public Future<Void> adddetails(final Supplier materialToAdd)
{
final Promise<Void> added = Promise.promise();
Future<Integer> fut1 = anAsyncAction_1(materialToAdd);
LOG.debug(" future.result() "+fut1.result());
fut1.compose((outcome) -> {
LOG.debug(" future.result() "+outcome);
});
CompositeFuture.all(fut1, fut2).onComplete(ar ->
{
System.out.println("BOTH OPERATION COMPLETED!! 1 " + ar.succeeded());
try
{
System.out.println("BOTH OPERATION COMPLETED!! 2 " + ar.result().list());
added.complete();
System.out.println("BOTH OPERATION COMPLETED!!");
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
});
return added.future();
}