Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code in original blog post (S3AsyncClient.getObject) not correct #381

Open
rmuller opened this issue Jan 8, 2018 · 3 comments
Open
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue

Comments

@rmuller
Copy link

rmuller commented Jan 8, 2018

This example code in the original blog post is not correct, see the same code in github repo:

public static void main(String[] args) {
    final S3AsyncClient client = S3AsyncClient.create();
    final CompletableFuture<GetObjectResponse> future = client.getObject(
        GetObjectRequest.builder()
            .bucket(BUCKET)
            .key("somedocument")
            .build(),
        AsyncResponseHandler.toFile(Paths.get("myfile.out")));
    future.whenComplete((resp, err) -> {
        try {
            if (resp != null) {
                System.out.println(resp);
            } else {
                err.printStackTrace();
            }
        } finally {
            FunctionalUtils.invokeSafely(client::close);
        }
    });
}

Notice that it is CompletableFuture<GetObjectResponse> instead of CompletableFuture<Void>.

Secondly, when this code is executed, it is returned immediately, without waiting for the task to finish.

@spfink
Copy link
Contributor

spfink commented Jan 12, 2018

The code in the blog post refers to 2.0.0-preview-1. Maybe when we go GA we'll update the blog post with updated code samples but we don't plan on doing it for each release during the developer preview.

@rmuller
Copy link
Author

rmuller commented Jan 15, 2018

Fair enough. My main point was, however, this sentence:

Secondly, when this code is executed, it is returned immediately, without waiting for the task to finish.

Or do I miss something?

@millems
Copy link
Contributor

millems commented Feb 2, 2018

We should update the example to wait for the download to finish before returning from the "main" method.

@justnance justnance added bug This issue is a bug. documentation This is a problem with documentation. and removed Documentation Issue labels Apr 19, 2019
@millems millems removed the bug This issue is a bug. label Jul 21, 2021
@yasminetalby yasminetalby added the p3 This is a minor priority issue label Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

5 participants