Skip to content

Instantly share code, notes, and snippets.

@eldermoraes
Created December 14, 2018 18:33
Show Gist options
  • Save eldermoraes/2611f5a9da9b91f09e650169c64cfaa7 to your computer and use it in GitHub Desktop.
Save eldermoraes/2611f5a9da9b91f09e650169c64cfaa7 to your computer and use it in GitHub Desktop.
public void book(TripReq input) {
Flow f = Flows.currentFlow();
FlowFuture<BookingRes> flightFuture =
f.invokeFunction("./flight/book", input.flight, BookingRes.class);
FlowFuture<BookingRes> hotelFuture =
f.invokeFunction("./hotel/book", input.hotel, BookingRes.class);
FlowFuture<BookingRes> carFuture =
f.invokeFunction("./car/book", input.carRental, BookingRes.class);
flightFuture.thenCompose(
(flightRes) -> hotelFuture.thenCompose(
(hotelRes) -> carFuture.whenComplete(
(carRes, e) -> EmailReq.sendSuccessMail(flightRes, hotelRes, carRes)
)
.exceptionallyCompose( (e) -> cancel("./car/cancel", input.carRental, e) )
)
.exceptionallyCompose( (e) -> cancel("./hotel/cancel", input.hotel, e) )
)
.exceptionallyCompose( (e) -> cancel("./flight/cancel", input.flight, e) )
.exceptionally( (err) -> {EmailReq.sendFailEmail(); return null;} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment