I want to have a Source that evaluates a function at given intervals and emits its output. As a workaround, I can do it with a Source.queue
+ offer
, but haven't found a cleaner way to do it. Ideally I would have something like
def myFunction() = .... // function with side-effects
Source.tick(1.second, 1.second, myFunction) // myFunction is evaluated at every tick
Any ideas?
Akka streams consist of three major components in it – Source, Flow and Sink.
The starting point is called Source and can be a collection, an iterator, a block of code which is evaluated repeatedly or a org.reactivestreams.Publisher. A flow with an attached input and open output is also a Source. A flow may also be defined without an attached input or output and that is then a Flow.
Kafka is an event streaming platform, loosely residing in the Message-Oriented Middleware (MoM) space. Akka is an Actor Model — a mechanism for concurrent computation based on the concepts of agents, immutability, and message passing.
Actor Materializer Lifecycle. The Materializer is a component that is responsible for turning the stream blueprint into a running stream and emitting the “materialized value”.
Probably the cleanest way is to use map
Source.tick(1.second, 1.second, NotUsed).map(_ ⇒ myFunction())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With