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

The following examples show how to use reactor.core.publisher.Mono#usingWhen() . These examples are extracted from open source projects. 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
<T> Mono<T> doInQueryRunnerForMono(final String targetDatabase, Function<RxQueryRunner, Mono<T>> func) {

		return Mono.usingWhen(retrieveRxStatementRunnerHolder(targetDatabase),
			holder -> func.apply(holder.getRxQueryRunner()),
			(holder, ex) -> holder.getRollback(),
Example 2
Source Project: james-project   File:    License: 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),
        (inputStream, throwable) -> closeResource(inputStream),
Example 3
Source Project: james-project   File:    License: 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))),
        (outputStream, throwable) -> closeResource(outputStream)
            .doFinally(any -> LOGGER.error("Error while backing up mailboxes for user {}", username.asString(), throwable)),
Example 4
private <T> Mono<T> usingConnection(Function<GatewayDiscordClient, Mono<T>> onConnectedFunction) {
    return Mono.usingWhen(login(), onConnectedFunction, GatewayDiscordClient::logout);