Java Code Examples for reactor.core.publisher.Mono#usingWhen()

The following examples show how to use reactor.core.publisher.Mono#usingWhen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultReactiveNeo4jClient.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
<T> Mono<T> doInQueryRunnerForMono(final String targetDatabase, Function<RxQueryRunner, Mono<T>> func) {

		return Mono.usingWhen(retrieveRxStatementRunnerHolder(targetDatabase),
			holder -> func.apply(holder.getRxQueryRunner()),
			RxStatementRunnerHolder::getCommit,
			(holder, ex) -> holder.getRollback(),
			RxStatementRunnerHolder::getCommit);
	}
 
Example 2
Source File: ExportService.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Mono<Task.Result> export(Progress progress, Username username) {
    return Mono.usingWhen(
        Mono.fromCallable(() -> zipMailboxesContent(progress, username)),
        inputStream -> export(progress, username, inputStream),
        this::closeResource,
        (inputStream, throwable) -> closeResource(inputStream),
        this::closeResource
    );
}
 
Example 3
Source File: ExportService.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Mono<Void> writeUserMailboxesContent(Username username, PipedOutputStream out) {
    return Mono.usingWhen(
        Mono.fromCallable(() -> out),
        outputStream -> Mono.fromRunnable(Throwing.runnable(() -> mailboxBackup.backupAccount(username, outputStream))),
        this::closeResource,
        (outputStream, throwable) -> closeResource(outputStream)
            .doFinally(any -> LOGGER.error("Error while backing up mailboxes for user {}", username.asString(), throwable)),
        this::closeResource);
}
 
Example 4
Source File: GatewayBootstrap.java    From Discord4J with GNU Lesser General Public License v3.0 4 votes vote down vote up
private <T> Mono<T> usingConnection(Function<GatewayDiscordClient, Mono<T>> onConnectedFunction) {
    return Mono.usingWhen(login(), onConnectedFunction, GatewayDiscordClient::logout);
}