Skip to content

Commit

Permalink
Merge pull request #487 from smallrye/feature/uni-replace-with-void
Browse files Browse the repository at this point in the history
Uni.replaceWithVoid
  • Loading branch information
cescoffier authored Feb 24, 2021
2 parents 33de98c + f246491 commit 1007d03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions implementation/src/main/java/io/smallrye/mutiny/Uni.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,20 @@ default Uni<T> replaceWithNull() {
return onItem().transform(ignore -> null);
}

/**
* Ignore the item emitted by this {@link Uni} and replace it with {@code null} and type {@link Void}.
* <p>
* This method is in effect similar to {@link Uni#replaceWithNull()}, except that it returns a {@code Uni<Void>}
* instead of a {@code Uni<T>}.
* <p>
* This is a shortcut for {@code uni.onItem().transform(ignored -> null)}.
*
* @return the new {@link Uni}
*/
default Uni<Void> replaceWithVoid() {
return onItem().transform(ignored -> null);
}

/**
* Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,15 @@ void replaceWithNull() {

subscriber.assertCompleted().assertItem(null);
}

@Test
@DisplayName("Replace with void")
void replaceWithVoid() {
UniAssertSubscriber<Void> subscriber = Uni.createFrom()
.item(69)
.replaceWithVoid()
.subscribe().withSubscriber(UniAssertSubscriber.create());

subscriber.assertCompleted().assertItem(null);
}
}

0 comments on commit 1007d03

Please sign in to comment.