Converting a Multi to Uni<Void> on completion

Viewed 133

What is the most suitable way to convert a Multi to Uni on completion? So far, I have the following working solutions:

multi.collect().asList().replaceWithVoid()

It just feels a bit odd to collect the items and to replace the list when I'm only interested in receiving an item upon completion. Am I missing a better solution?

1 Answers

You can simply skip all Multi emitted items then switch over to a Uni:

multi.skip()
     .where(ignored -> true)
     .toUni()
     //.replaceWithVoid()

Optionally using the Uni#replaceWithVoid as you suggested to switch the Uni formal type.

The difference would be to avoid storing elements temporarily in memory using the Multi#collect operator. Now you are simply ignoring the items and switching downstream on completion.

Related