Uni and Multi#
Mutiny defines two reactive types:
Multi
- represents streams of 0..* items (potentially unbounded)Uni
- represents streams receiving either an item or a failure
Tip
The Mutiny name comes from the contraction of Multi
and Uni
names
Both Uni
and Multi
are asynchronous types.
They receive and fire events at any time.
You may wonder why we make the distinction between Uni
and Multi.
Conceptually, a Uni
is a Multi,
right?
In practice, you don’t use Unis
and Multis
the same way.
The use cases and operations are different.
Uni
does not need the complete ceremony presented above as the request does not make sense.- The
subscribe
event expresses the interest and triggers the computation, no need for an additional request. Uni
can handle items having anull
value (and has specific methods to handle this case).Multi
does not allow it (because the Reactive Streams specification forbids it).- Having a
Uni
implementingPublisher
would be a bit like havingOptional
implementingIterable
.
In other words, Uni
:
- can receive at most 1
item
event, or afailure
event - cannot receive a
completion
event (null
in the case of 0 items) - cannot receive a
request
event
The following snippet shows how you can use Uni
and Multi
: