This is the API documentation for the Monifu library.
Monifu is a high-performance Scala / Scala.js library for
composing asynchronous and event-based programs using observable sequences
that are exposed as asynchronous streams, expanding on the
strongly inspired by
Reactive Extensions (Rx),
but designed from the ground up for back-pressure and made to cleanly interact
with Scala's standard library and compatible out-of-the-box with the
Reactive Streams protocol.
In order for subscriptions to work, we need an implicit
Scheduler imported in our
context. A Scheduler inherits from Scala's own
and any ExecutionContext can be quickly converted into a Scheduler.
And then you're off ...
// is being used under the hood
// or we can simply convert our own execution context
// import play.api.libs.concurrent.Execution.Implicits.defaultContext
// implicit val scheduler = Scheduler(defaultContext)
val subscription = Observable.intervalAtFixedRate(1.second)
.subscription(x => println(x))
We can then try out more complex things:
// emits an auto-incremented number, every second
// drops the items emitted over the first 5 secs
// takes the first 100 emitted events
// per second, makes requests and concatenates the results
.flatMap(x => WS.request(s"http://some.endpoint.com/request?tick=$x").get())
// filters only valid responses
.filter(response => response.status == 200)
// samples by 3 seconds, repeating previous results in case of nothing new
// processes response, selecting the body
.map(response => response.body)
// creates subscription, foreach response print it
.foreach(x => println(x))
There's actually a lot more to Monifu.