com.azure.core.util.AsyncCloseable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-core Show documentation
Show all versions of azure-core Show documentation
This package contains core types for Azure Java clients.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.core.util;
import reactor.core.publisher.Mono;
/**
* Interface for close operations that are asynchronous.
*
* Asynchronously closing a class
* In the snippet below, we have a long-lived {@code NetworkResource} class. There are some operations such
* as closing {@literal I/O}. Instead of returning a sync {@code close()}, we use {@code 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();
*
*
*/
public interface AsyncCloseable {
/**
* 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.
*
* @return A Mono representing the close operation. If the close operation is unsuccessful, the Mono completes with
* an error.
*/
Mono closeAsync();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy