Skip to content

Instantly share code, notes, and snippets.

@WadeWaldron
Created November 20, 2014 23:11
Show Gist options
  • Save WadeWaldron/cfe61bf8af2e221596fd to your computer and use it in GitHub Desktop.
Save WadeWaldron/cfe61bf8af2e221596fd to your computer and use it in GitHub Desktop.
Streaming Play Enumerators through Spray (package)
import akka.actor.{ActorContext, ActorRefFactory, Props}
import play.api.libs.iteratee.Enumerator
import spray.http.{HttpData, ContentType}
import spray.routing.RequestContext
import scala.concurrent.ExecutionContext
package object chunkedresponses {
implicit class ChunkedRequestContext(requestContext: RequestContext) {
def completeChunked(contentType: ContentType, enumerator: Enumerator[HttpData])
(implicit executionContext: ExecutionContext, actorRefFactory: ActorRefFactory) {
val chunkedResponder = actorRefFactory.actorOf(Props(new ChunkedResponder(contentType, requestContext.responder)))
val iteratee = new ChunkIteratee(chunkedResponder)
enumerator.run(iteratee)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment