From a2fc1e855977c4df56a8a3cc6368a2b44758ea4c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 11:05:00 +0000 Subject: [PATCH 1/2] Initial plan From 1c56f39f42328b19b54d752562672034221b9033 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 11:09:57 +0000 Subject: [PATCH 2/2] Fix async sample patterns with CountDownLatch timeout Co-authored-by: changjian-wang <15209050+changjian-wang@users.noreply.github.com> --- .../samples/Sample00_UpdateDefaultsAsync.java | 13 ++++++++++--- .../samples/Sample06_GetAnalyzerAsync.java | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample00_UpdateDefaultsAsync.java b/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample00_UpdateDefaultsAsync.java index ce6a1b66512d..fbc7f7a8ba76 100644 --- a/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample00_UpdateDefaultsAsync.java +++ b/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample00_UpdateDefaultsAsync.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** @@ -64,6 +65,9 @@ public static void main(String[] args) { // Step 1: Get current defaults to see what's configured System.out.println("Getting current default configuration..."); + // Use CountDownLatch to wait for async operation to complete + CountDownLatch latch = new CountDownLatch(1); + // Chain all operations reactively client.getDefaults() .doOnNext(currentDefaults -> { @@ -114,6 +118,7 @@ public static void main(String[] args) { System.err.println("Error occurred: " + error.getMessage()); error.printStackTrace(); }) + .doFinally(signalType -> latch.countDown()) .subscribe( result -> { // Success - operations completed @@ -124,10 +129,12 @@ public static void main(String[] args) { } ); - // The .subscribe() creation is not a blocking call. For the purpose of this example, - // we sleep the thread so the program does not end before the async operations complete. + // Wait for the async operation to complete with a timeout try { - TimeUnit.SECONDS.sleep(10); + if (!latch.await(30, TimeUnit.SECONDS)) { + System.err.println("Operation timed out after 30 seconds"); + System.exit(1); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); e.printStackTrace(); diff --git a/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample06_GetAnalyzerAsync.java b/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample06_GetAnalyzerAsync.java index f9b91a744b3f..049c9cc778d4 100644 --- a/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample06_GetAnalyzerAsync.java +++ b/sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample06_GetAnalyzerAsync.java @@ -11,6 +11,7 @@ import com.azure.identity.DefaultAzureCredentialBuilder; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; /** * Sample demonstrating how to get analyzer information asynchronously. @@ -124,9 +125,12 @@ public static void main(String[] args) { ); // END:ContentUnderstandingGetAnalyzerAsync - // Wait for the async operation to complete + // Wait for the async operation to complete with a timeout try { - latch.await(); + if (!latch.await(10, TimeUnit.SECONDS)) { + System.err.println("Operation timed out after 10 seconds"); + System.exit(1); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); e.printStackTrace();