I have data arriving at an actor in chunks and would like to return those chunks as a stream in a Play Result
. Since the only way to get a response from Ok.stream
looks like the ideal candidate, something like this:
Action.async { request =>
(source ? GetStream()).map {
case enumerator => Ok.stream(enumerator)
}
}
I'd be returning a Enumerator[Array[Byte]]
from my actor and then inside the actor keep pushing chunks into the enumerator as messages arrive at the actor. However: Returning a mutable Enumerator from an actor definitely seems like a violation of some kind.
Is there a more appropriate way to accomplish this? I figured either akka-stream
or akka.io
would be abstractions that might address the problem space, but I can't see how they would apply.