Skip to content

Commit

Permalink
Make completion of download async
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 13, 2024
1 parent dfbc999 commit d3c64e0
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void download(DownloadRequest request, StreamObserver<DownloadResponse> r

try {
var proxy = RPCUtils.convertProxy(request::hasProxy, request::getProxy);
responseObserver.onNext(ReactorHttpHelper.createReactorClient(proxy, false)
ReactorHttpHelper.createReactorClient(proxy, false)
.headers(h -> request.getHeadersList().forEach(header -> h.set(header.getKey(), header.getValue())))
.get()
.uri(URI.create(request.getUri()))
Expand All @@ -59,12 +59,16 @@ public void download(DownloadRequest request, StreamObserver<DownloadResponse> r
.build()).toList())
.setStatusCode(res.status().code())
.build()))
.toFuture()
.join()
);
.subscribe(response -> {
responseObserver.onNext(response);
responseObserver.onCompleted();
}, t -> {
log.error("Error downloading data", t);
responseObserver.onError(new StatusRuntimeException(Status.INTERNAL.withDescription(t.getMessage()).withCause(t)));
});
responseObserver.onCompleted();
} catch (Throwable t) {
log.error("Error authenticating account", t);
log.error("Error downloading data", t);
throw new StatusRuntimeException(Status.INTERNAL.withDescription(t.getMessage()).withCause(t));
}
}
Expand Down

0 comments on commit d3c64e0

Please sign in to comment.