reactor / reactor-core

Non-Blocking Reactive Foundation for the JVM
http://projectreactor.io
Apache License 2.0
4.93k stars 1.2k forks source link

Allow Supplier to be used with .then/thenReturn #3850

Closed fcappi closed 2 months ago

fcappi commented 2 months ago

Summary

Provide a way for using a Supplier with then() operator

Motivation

We always need to use Mono.supplier on .then() operator to avoid code being executed on assembly time. So the goal is to save some lines of code since this is a recurrent need.

Desired solution

Mono thenReturn(Supplier supplier) or Mono then(Supplier supplier) ## Considered alternatives .then(Mono.fromSupplier(() -> {...}))
chemicL commented 2 months ago

Hey @fcappi. As you noticed, .then(Mono.fromSupplier(...)) is accomplishing what you are looking for. There have been similar requests in the past (#2464, #3640) and they have been declined due to existing API combinations that allow to reach the end goal and because growing the API to minize typing is not a goal for the project ATM. The easiest implementation for this would be to just delegate to Mono.fromSupplier and aside from saving a few key strokes it brings no performance benefit or others for the cost of added API surface and maintenance cost. With that, I'm sorry to decline the proposal at this time.