-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Labels
enhancementgood first issuegroomedThe issue has been groomed and should be in a good shape.The issue has been groomed and should be in a good shape.hacktoberfesthelp wantedup-for-grabs
Description
Motivation
After updating a large application to the latest version of the Java SDK, all calls to the DeliveryClient had to wrapped in a synchronous wrapper. It would be helpful if there were a built-in way to call the DeliveryClient synchronously rather than introducing additional code to the project.
Proposed solution
Add alternate methods for working with the DeliveryClient synchronously, for example:
deliveryClient.getItems().toSync() or deliveryClient.getItemsSynchronously()
Additional context
Here is the wrapper class that I had to write:
public class DeliveryClientHelper {
public static <T> T toSync(CompletionStage<T> completionStage) {
try {
return completionStage.toCompletableFuture().get();
} catch (InterruptedException e) {
log.error("Error converting completion stage: {}", e.getMessage());
} catch (ExecutionException e) {
log.error("Error converting completion stage: {}", e.getMessage());
}
return null;
}
}
An example call using the wrapper:
List<AgencySiteBlogLanding> blogHomepages = DeliveryClientHelper.toSync(deliveryClient.getItems(AgencySiteBlogLanding.class));
An ideal way to use the DeliveryClient
List<AgencySiteBlogLanding> blogHomepages = deliveryClient.getItems(AgencySiteBlogLanding.class).toSync();
Metadata
Metadata
Assignees
Labels
enhancementgood first issuegroomedThe issue has been groomed and should be in a good shape.The issue has been groomed and should be in a good shape.hacktoberfesthelp wantedup-for-grabs