AsyncCloseable Interface
public interface AsyncCloseable
Interface for close operations that are asynchronous.
Asynchronously closing a class
In the snippet below, we have a long-lived NetworkResource
class. There are some operations such as closing I/O. Instead of returning a sync close()
, we use closeAsync()
so users' programs don't block waiting for this operation to complete.
NetworkResource resource = new NetworkResource();
resource.longRunningDownload("https://longdownload.com")
.subscribe(
byteBuffer -> System.out.println("Buffer received: " + byteBuffer),
error -> System.err.printf("Error occurred while downloading: %s%n", error),
() -> System.out.println("Completed download operation."));
System.out.println("Press enter to stop downloading.");
System.in.read();
// We block here because it is the end of the main Program function. A real-life program may chain this
// with some other close operations like save download/program state, etc.
resource.closeAsync().block();
Method Summary
Modifier and Type | Method and Description |
---|---|
abstract Mono<Void> |
closeAsync()
Begins the close operation. |
Method Details
closeAsync
public abstract Mono
Begins the close operation. If one is in progress, will return that existing close operation. If the close operation is unsuccessful, the Mono completes with an error.
Returns:
A Mono representing the close operation. If the close operation is unsuccessful, the Mono completes with
an error.
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
Azure SDK for Java