Rohit Bajaj
asked on
Using completionStage Properly
Hi,
There is following code -
The getEmailMapping function is a synchronous call so when the code gets executed the result will be there.
To give the context there is a Boolean attribute inside GetMappingResponsePayload and based on that
i want to return an exceptionallyCompletedFutu re in case the value is false.
otherwise the next return statement is executed.
How do i achieve this neatly
Thanks
There is following code -
public CompletionStage<Void> addEmail(Long userID, String email) {
CompletableFuture<GetMappingResponsePayload> getMappingResponsePayloadCompletionStage =
(CompletableFuture<GetMappingResponsePayload>) addressResolver.getEmailMapping(email);
return addressResolver.addEmailMapping(email, userID)
.thenCompose(__ -> emailsDao.upsertEmail(userID, email, true));
I want to fetch the object GetMappingResponsePayload from above.The getEmailMapping function is a synchronous call so when the code gets executed the result will be there.
To give the context there is a Boolean attribute inside GetMappingResponsePayload and based on that
i want to return an exceptionallyCompletedFutu
otherwise the next return statement is executed.
How do i achieve this neatly
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
This may seem somewhat different from what i posted.. But the essential thing here is instead of get i used thenAccept and assigned the boolean from inside of the lambda expression..And now i can directly use this boolean.
Please suggest any pros and cons of this approach