thenRunnable

fun Mono<*>.thenRunnable(runnable: () -> Unit): Mono<Void>

Executes a runnable after this Mono completes successfully.

This extension function allows you to perform side effects (like logging, cleanup, or notifications) after the current Mono completes. The runnable is executed regardless of whether the Mono produces a value or is empty.

The returned Mono emits Void when the runnable completes, making it suitable for chaining additional operations that depend on the side effect completion.

Example usage:

val result = orderService.processOrder(order)
.thenRunnable {
// Log successful order processing
logger.info("Order ${order.id} processed successfully")
}
.thenRunnable {
// Send notification
notificationService.sendOrderConfirmation(order.customerId)
}
.thenReturn("Order processed")

Return

a Mono that emits Void after the runnable completes

Parameters

runnable

a function to execute after this Mono completes

See also

Mono.fromRunnable