Skip to content

Commit

Permalink
Don't use CompletableFuture::join in the default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mizosoft committed Dec 20, 2024
1 parent c298105 commit b29e583
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import com.github.mizosoft.methanol.internal.Utils;
import com.github.mizosoft.methanol.internal.adapter.BasicAdapter;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpResponse.BodySubscriber;
Expand Down Expand Up @@ -170,7 +173,13 @@ default <T> BodySubscriber<Supplier<T>> toDeferredObject(
toObject(typeRef, mediaType),
subscriber ->
CompletableFuture.completedStage(
() -> subscriber.getBody().toCompletableFuture().join()));
() -> {
try {
return Utils.getIo(subscriber.getBody().toCompletableFuture());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.github.mizosoft.methanol.MoreBodySubscribers;
import com.github.mizosoft.methanol.TypeRef;
import com.github.mizosoft.methanol.internal.Utils;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpResponse.BodySubscriber;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -216,7 +218,13 @@ default <T> BodySubscriber<Supplier<T>> toDeferredObject(TypeRef<T> typeRef, Hin
toObject(typeRef, hints),
subscriber ->
CompletableFuture.completedStage(
() -> subscriber.getBody().toCompletableFuture().join()));
() -> {
try {
return Utils.getIo(subscriber.getBody().toCompletableFuture());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
}
}
}

0 comments on commit b29e583

Please sign in to comment.