§Reactive Streams integration (experimental)
Play experimental libraries are not ready for production use. APIs may change. Features may not work properly.
Reactive Streams is a specification and SPI that is currently under development. Reactive Streams provides a common standard that allows different stream implementations to be connected together. The SPI is quite small, with just a few simple interfaces such as Publisher and Subscriber.
Play 2.4 provides an experimental Reactive Streams integration module that adapts Futures, Promises, Enumerators and Iteratees into Reactive Streams’ Publishers and Subscribers.
§Known issues
- The implementations haven’t been fully updated to verson 0.4 of the Reactive Streams specification. For example,
Publishers andSubscribers may send or accept anonCompleteevent without a precedingonSubscribeevent. This was allowed in 0.3 but is not permitted in 0.4. - May need to lift
Inputevents into the stream to ensure thatInput.EOFevents cannot be lost and to provide proper support forInput.Empty. At the moment there is the potential for event loss when adapting iteratees and enumerators. - No performance tuning has been done.
- Needs support for two-way conversion between all the main stream and iteratee types.
- Documentation is limited.
- Test that the module works from Java.
§Usage
Include the Reactive Streams integration library into your project.
libraryDependencies += "com.typesafe.play" %% "play-streams-experimental" % "2.4.0-M2"
All access to the module is through the Streams object.
Here is an example that adapts a Future into a single-element Publisher.
val fut: Future[Int] = Future { ... }
val pubr: Publisher[Int] = Streams.futureToPublisher(fut)
See the Streams object’s API documentation for more information.
Next: Hacking Play