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

Waiters #24

Closed
millems opened this issue Jul 3, 2017 · 6 comments
Closed

Waiters #24

millems opened this issue Jul 3, 2017 · 6 comments
Labels
1.x Parity feature-request A feature should be added or improved.

Comments

@millems
Copy link
Contributor

millems commented Jul 3, 2017

Review the inherited state of V1 waiters and determine which changes are necessary for V2.

(Feel free to comment on this issue with desired changes).

@rleibman
Copy link

This is what I'm doing in Scala using the async clients. I imagine you could do something similar in java.

def whileInProgress[Request <: AmazonWebServiceRequest, Response](
    method: Request => java.util.concurrent.CompletableFuture[Response],
    request: Request,
    isInProgress: Response ⇒ Boolean,
    duration: Duration = 30 seconds): Future[Response] = {
    def loop(): Future[Response] = {
      val fut = method(request).toScala
      fut.flatMap { response =>
        if (isInProgress(response)) {
          Thread.sleep(duration.toMillis)
          loop
        }
        fut
      }
    }

    loop
  }

millems added a commit that referenced this issue Oct 25, 2017
This was a direct copy of the 1.11.x waiters, and we intend to update
them for 2.x: #24
millems added a commit that referenced this issue Oct 25, 2017
This was a direct copy of the 1.11.x waiters, and we intend to update
them for 2.x: #24
@spfink
Copy link
Contributor

spfink commented Mar 12, 2019

Feature Request from v1: aws/aws-sdk-java#815

@yellowstonesoftware
Copy link

Is this ever going to be implemented?

@millems
Copy link
Contributor Author

millems commented Apr 10, 2019

Yes. Unfortunately, we cannot provide a date.

@justnance justnance added feature-request A feature should be added or improved. and removed Feature Request labels Apr 19, 2019
@millems millems changed the title Refactor: Waiters Waiters Jul 8, 2019
@zoewangg
Copy link
Contributor

zoewangg commented Oct 1, 2020

Hey all, we have released waiters in 2.15.0.

Below is the sample code of how to use it:

  • sync waiter:
DynamoDbClient dynamo = DynamoDbClient.create();
DynamoDbWaiter waiter = dynamo.waiter();

WaiterResponse<DescribeTableResponse> waiterResponse =
   waiter.waitUntilTableExists(r -> r.tableName("myTable"));

// print out the matched response with a tableStatus of ACTIVE
waiterResponse.matched().response().ifPresent(System.out::println);
  • async waiter
DynamoDbAsyncClient asyncDynamo = DynamoDbAsyncClient.create();
DynamoDbAsyncWaiter asyncWaiter = asyncDynamo.waiter();

CompletableFuture<WaiterResponse<DescribeTableResponse>> waiterResponse =
                    asyncWaiter.waitUntilTableNotExists(r -> r.tableName("myTable"));

waiterResponse.whenComplete((r, t) -> {
   if (t == null) {
      // print out the matched ResourceNotFoundException
      r.matched().exception().ifPresent(System.out::println);
   }
}).join();

To learn more, check out our blog post and developer guide:

https://aws.amazon.com/blogs/developer/using-waiters-in-the-aws-sdk-for-java-2-x/
https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/waiters.html

Let us know if you have any feedback! 😃

@zoewangg zoewangg closed this as completed Oct 1, 2020
@cartwrightian
Copy link

all works well, many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Parity feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

7 participants