-
Notifications
You must be signed in to change notification settings - Fork 2k
Frequently Asked Questions
The Java client library asynchronous methods returns reactive types - Flux<T>
and Mono<T>
, or types extending from these.
These reactive types are referred to as "cold". That is, all underlying work will not be activated without a subscription. When an application invokes an async method, it will return without receiving any result. Only once a subscription is added will work be initiated to receive results.
The simplest way to create a subscription is to call subscribe()
on the reactive type, but sometimes even after subscription you might not receive result. Consider the following example:
Mono<Response<Key>> result = asyncClient.getKey();
result.subscribe(response -> {
System.out.println(response.value());
});
While the subscribe()
call causes execution of the underlying work that makes an API call to retrieve the key, sometimes the lambda provided to print out the response value does not get called.
The reason for this is obvious in hindsight: reactive types are asynchronous. The rest of the application continues to operate as per usual, and this includes having the application exit before the results are returned!
Knowing this, the easiest means to block execution and be sure you get the results before your application continues execution (and / or exits) is to use the various block
calls available, for example:
Mono<Response<Key>> result = asyncClient.getKey();
result.subscribe(response -> {
System.out.println(response.value());
}).block();
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers