Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down