I have an application which is built on top of the Play/Lagom stack. I need to call a service which requires Source[T, NotUsed]
to stream a file to it. This is the interface of the service:
def foo(fooId: UUID): ServiceCall[Source[ByteString, NotUsed], Source[String, NotUsed]]
I am therefore using Accumulator.source
from the Play documentation, in the following way:
private def doSomething(fooId: UUID): BodyParser[Future[Seq[String]]] = BodyParser { _ =>
Accumulator.source[ByteString]
.mapFuture { source: Source[ByteString, NotUsed] =>
externalService
.foo(fooId)
.invoke(source)
.map { x =>
Right(x.runWith(Sink.seq[String]))
}
}
}
Now, inside the mapFuture
call, source
's type is Source[ByteString, _]
, but if I change it to Source[ByteString, NotUsed]
in order to call the service, as in the example above, I'm getting an error in the IDE that
Source[ByteString, _]
is expected. Isn't _
supposed to mean that I can change the type to whatever I want to, including NotUsed
? On the other hand, shouldn't these two be semantically equivalent anyway? I found out that the Akka team introduced akka.NotUsed
to replace Unit
for when materialized values don't matter in some previous versions, but that still doesn't give me a clue on how to solve my problem.
The above snippet is similar to this example in the Play documentation on directing the body elsewhere.