mutiny-kotlin provides an integration with Kotlin for use with coroutines and convenient language features.
There are extension methods available for converting between Mutiny and Kotlin (coroutine) types. For implementation details please have also a look to these methods’ documentation.
The coroutine extension functions are shipped in the package
You need to add the following dependency to your project:
Awaiting a Uni in coroutines#
Within a coroutine or suspend function you can easily await Uni events in a suspended way:
Processing a Multi as Flow#
Flow type matches
Multi semantically, even though it isn’t a feature complete reactive streams implementation.
You can process a
Flow as follows:
There’s no flow control availabe for Kotlin’s
Flow. Published items are buffered for consumption using a coroutine
The buffer size and overflow strategy of that
Channel can be configured using optional arguments:
Multi.asFlow(bufferCapacity = Channel.UNLIMITED, bufferOverflowStrategy = BufferOverflow.SUSPEND),
for more details please consult the method documentation.
Providing a Deferred value as Uni#
The other way around is also possible, let a Deferred become a Uni:
Creating a Multi from a Flow#
Finally, creating a Multi from a Flow is also possible:
Unit instead of Void (null) value#
Kotlin has a special value type
Unit similar to Java’s
Uni<Void> holds a
null item, you can get a
Unit by using the extension function
Uni from Kotlin code can easily be achieved using the following builders available as regular or coroutine variant: