Promise.thenMap - advantageous/reakt GitHub Wiki
The method Promise.thenMap
converts one type of promise into another.
Let's say for example you are storing data into Cassandra.
You want to convert a promise that returns a Cassandra ResultSet
into a promise that returns a Boolean
.
final Promise<ResultSet> resultSetPromise = Promises.<ResultSet>promise();
final Promise<Boolean> promise = resultSetPromise
.thenMap(ResultSet::wasApplied) // <-------------- see thenMap
.catchError((error) -> {
if (error instanceof DriverException) {
logger.error("Error " + message, error);
errorCount.incrementAndGet();
}
});
/* registerCallback is from Reakt Guava Bridge
It converts ListableFutures into Reakt promises (to/fro).
*/
registerCallback(resultSetFuture, resultSetPromise);
Here is a simpler example that turns an Employee Promise into a Sheep Promise.
Promise<Employee> employeePromise = Promises.<Employee>promise();
Promise<Sheep> sheepPromise = employeePromise
.thenMap(employee1 -> new Sheep(employee1.id));
employeeService.lookupEmployee("id123", employeePromise);