I need some help to pass parameter from one compose to another. I want to pass the labelParemeters in the second compose into the last compose, as I have shown in the code below.
public Future<JsonArray> startTest(int jobID, RoutingContext context) {
LOG.info("-----INside startTest() method-----");
return jobDao.getJob(jobID, context)
.compose(job -> productDao.getLabelParameters(job, context))
.compose(labelParameters -> jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters))
.compose(parentChildSerials -> {
LOG.debug(" Future Returned Job Parent-Child to Print: ");
prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here
return Future.succeededFuture(parentChildSerials);
})
.onFailure(error -> {
LOG.debug("startTest() Failed: ", error);
})
.onSuccess(server -> {
LOG.debug("Finished startTest!!");
LOG.debug(server.encodePrettily());
});
}
You can create a context object the has setters/getter for the data that is passed around in the Futures. Compose guareantees serial execution of your Futures, you can set the results and assume that the result is present in your context object in the next compose section. Example:
You can also make use of the java records for this.
Alternatively you can nest the compose parts as follows: