Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce MonoFromFutureSupplier{,Boolean} Refaster rules #1244

Merged
merged 2 commits into from
Jul 20, 2024

Conversation

Venorcis
Copy link
Contributor

Futures subscribe eagerly. This means that Mono#fromFuture(CompletableFuture) already executes the contents of the future on assembly time (even when that Future is constructed from a Mono as we do in our reactive Caffeine caches).

I therefore suggest instead to always use Mono#fromFuture(Supplier), which will only instantiate (and thus execute) the future on subscription, i.e. much closer to how we usually do everything 😄

@Venorcis Venorcis requested a review from Stephan202 July 12, 2024 15:02
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Venorcis Venorcis changed the title Prefer the lazy version of Mono#fromFuture Prefer the lazy version of Mono#fromFuture Jul 15, 2024
@rickie rickie self-requested a review July 17, 2024 06:12
@rickie rickie added this to the 0.17.0 milestone Jul 19, 2024
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Nice one @Venorcis :).

Suggested commit message:

Introduce `MonoFromFuture{,SuppressCancel}` Refaster rule (#1244)

(Commit message pending the rename comment ofcourse)

* Prefer {@link Mono#fromFuture(Supplier, boolean)} over {@link
* Mono#fromFuture(CompletableFuture, boolean)}.
*/
static final class MonoFromFutureSuppressCancel<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stephan202 according to our undocumented naming scheme, we would now call this MonoFromFutureBoolean right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking even MonoFromFutureSupplierBoolean 😄

@Stephan202 Stephan202 force-pushed the vkoeman/mono-from-future branch from 3561c90 to a005e37 Compare July 20, 2024 09:14
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit. Updated suggested commit message:

Introduce `MonoFromFutureSupplier{,Boolean}` Refaster rules (#1244)

* Prefer {@link Mono#fromFuture(Supplier, boolean)} over {@link
* Mono#fromFuture(CompletableFuture, boolean)}.
*/
static final class MonoFromFutureSuppressCancel<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking even MonoFromFutureSupplierBoolean 😄

Comment on lines +1911 to +1919
@BeforeTemplate
Mono<T> before(CompletableFuture<T> future) {
return Mono.fromFuture(future);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add an XXX to later apply @NotMatches(IsIdentityOperation.class). Cause as-is this code will also rewrite Mono.fromFuture(someVariable), which isn't great.

@Stephan202 Stephan202 changed the title Prefer the lazy version of Mono#fromFuture Introduce MonoFromFutureSupplier{,Boolean} Refaster rules Jul 20, 2024
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

@rickie rickie merged commit 4b1c892 into master Jul 20, 2024
15 checks passed
@rickie rickie deleted the vkoeman/mono-from-future branch July 20, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants