
io.github.numichi.reactive.logger.reactor.kotlin.kotlin-extensions.kt Maven / Gradle / Ivy
package io.github.numichi.reactive.logger.reactor.kotlin
import kotlinx.coroutines.reactor.mono
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
fun Flux.logOnNext(logger: (T) -> Mono<*>): Flux {
return this.flatMap { logger(it).thenReturn(it) }
}
fun Mono.logOnNext(logger: (T) -> Mono<*>): Mono {
return this.flatMap { logger(it).thenReturn(it) }
}
fun Flux.logOnNextCoroutine(logger: suspend (T) -> Unit): Flux {
return this.flatMap { value ->
mono {
logger(value)
value
}
}
}
fun Mono.logOnNextCoroutine(logger: suspend (T) -> Unit): Mono {
return this.flatMap { value ->
mono {
logger(value)
value
}
}
}
fun Flux.logOnError(logger: (Throwable) -> Mono<*>): Flux {
return this.onErrorResume { throwable ->
logger(throwable)
.then(Mono.error(throwable))
}
}
fun Mono.logOnError(logger: (Throwable) -> Mono<*>): Mono {
return this.onErrorResume { throwable ->
logger(throwable)
.then(Mono.error(throwable))
}
}
fun Flux.logOnErrorCoroutine(logger: suspend (Throwable) -> Unit): Flux {
return this.onErrorResume { throwable ->
mono {
logger(throwable)
throw throwable
}
}
}
fun Mono.logOnErrorCoroutine(logger: suspend (Throwable) -> Unit): Mono {
return this.onErrorResume { throwable ->
mono {
logger(throwable)
throw throwable
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy