Skip to content

JDK Flow from/to Reactive Streams Adapters#

The mutiny-zero-flow-adapters library (Maven coordinates io.smallrye.reactive:mutiny-zero-flow-adapters) provides a clean room implementation of adapters from and to the JDK Flow interfaces that match those from Reactive Streams.

Why another adapter library?#

The implementation of our adapters is similar in spirit to those from the Reactive Streams library, but they differ by:

  • failing early rather than passing null through in some cases,
  • shipping under a proper open source license while the Reactive Streams library took a long time to make any progress towards publishing a new release, see #536 and #530
  • having correct JPMS (Java modules) descriptors for those who might need modules rather than the classpath.

How to use it?#

The public API exposes 2 types:

  • AdaptersToFlow to convert Reactive Streams types to Flow types, and
  • AdaptersToReactiveStreams to convert Flow types to Reactive Streams types.

Each type offers factory methods to convert from one type to the other. For instance here’s how you can convert from a Reactive Streams Publisher to a Flow.Publisher:

Publisher<String> rsPublisher = connect("foo"); // ... where 'connect' returns a Publisher<String>

Flow.Publisher<String> flowPublisher = AdaptersToFlow.publisher(rsPublisher);