reactor.core.publisher.MonoExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/*
* Copyright (c) 2011-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reactor.core.publisher
import org.reactivestreams.Publisher
import java.util.concurrent.Callable
import java.util.concurrent.CompletableFuture
import java.util.function.Supplier
import kotlin.reflect.KClass
/**
* Extension to convert any [Publisher] of [T] to a [Mono] that only emits its first
* element.
*
* Note this extension doesn't make much sense on a [Mono] but it won't be converted so it
* doesn't hurt.
*
* @author Simon Baslé
* @since 3.1.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun Publisher.toMono(): Mono = Mono.from(this)
/**
* Extension to convert any [Supplier] of [T] to a [Mono] that emits supplied element.
*
* @author Sergio Dos Santos
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun (() -> T?).toMono(): Mono = Mono.fromSupplier(this)
/**
* Extension for transforming an object to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun T.toMono(): Mono = Mono.just(this)
/**
* Extension for transforming an [CompletableFuture] to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun CompletableFuture.toMono(): Mono = Mono.fromFuture(this)
/**
* Extension for transforming an [Callable] to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun Callable.toMono(): Mono = Mono.fromCallable(this::call)
/**
* Extension for transforming an exception to a [Mono] that completes with the specified error.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("toMono()", "reactor.kotlin.core.publisher.toMono"))
fun Throwable.toMono(): Mono = Mono.error(this)
/**
* Extension for [Mono.cast] providing a `cast()` variant.
*
* @author Sebastien
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("cast()", "reactor.kotlin.core.publisher.cast"))
inline fun Mono<*>.cast(): Mono = cast(T::class.java)
/**
* Extension for [Mono.doOnError] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("doOnError(exceptionType, onError)", "reactor.kotlin.core.publisher.doOnError"))
fun Mono.doOnError(exceptionType: KClass, onError: (E) -> Unit): Mono =
doOnError(exceptionType.java) { onError(it) }
/**
* Extension for [Mono.onErrorMap] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("onErrorMap(exceptionType, mapper)", "reactor.kotlin.core.publisher.onErrorMap"))
fun Mono.onErrorMap(exceptionType: KClass, mapper: (E) -> Throwable): Mono =
onErrorMap(exceptionType.java) { mapper(it) }
/**
* Extension for [Mono.ofType] providing a `ofType()` variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("ofType()", "reactor.kotlin.core.publisher.ofType"))
inline fun Mono<*>.ofType(): Mono = ofType(T::class.java)
/**
* Extension for [Mono.onErrorResume] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("onErrorResume(exceptionType, fallback)", "reactor.kotlin.core.publisher.onErrorResume"))
fun Mono.onErrorResume(exceptionType: KClass, fallback: (E) -> Mono): Mono =
onErrorResume(exceptionType.java) { fallback(it) }
/**
* Extension for [Mono.onErrorReturn] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("onErrorReturn(exceptionType, value)", "reactor.kotlin.core.publisher.onErrorReturn"))
fun Mono.onErrorReturn(exceptionType: KClass, value: T): Mono =
onErrorReturn(exceptionType.java, value)
/**
* Extension for [Mono.switchIfEmpty] accepting a function providing a Mono. This allows having a deferred execution with
* the [switchIfEmpty] operator
*
* @author Kevin Davin
* @since 3.2
*/
@Deprecated("To be removed in 3.3.0.RELEASE, replaced by module reactor-kotlin-extensions",
ReplaceWith("switchIfEmpty(s)", "reactor.kotlin.core.publisher.switchIfEmpty"))
fun Mono.switchIfEmpty(s: () -> Mono): Mono = this.switchIfEmpty(Mono.defer { s() })
© 2015 - 2025 Weber Informatics LLC | Privacy Policy