public interface AsyncCloseable
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();
| Modifier and Type | Method and Description |
|---|---|
Mono<Void> |
closeAsync()
Begins the close operation.
|
Mono<Void> closeAsync()
Copyright © 2021 Microsoft Corporation. All rights reserved.