What's the use and meaning of second type parameter in akka.Source
?
Sample Code:-
def stream: ServiceCall[Source[String, NotUsed], Source[String, NotUsed]]
According to as much code I have seen up to now by default second type parameter is set to akka.NotUsed
. But I don't know what's the significance of it.
The second parameter is the materialized value, that is, when you run the source, it's the value that gets returned by the
run
method to you. All stream shapes in Akka streams have them, that is, sources, sinks, flows, bidiflows, etc. With sinks, it's really obvious, if you're folding the stream, you're going to end up with a single value, that value is given to you through the materialized value, which is a future of the result:For sources though, it's less obvious, but here's one example:
This is a
Source
that, when you run it, materializes to anActorRef
. Every message that you send to the actor will be emitted from the source. If you wanted to use this in Lagom, you would do something like this: