Menu
  • HOME
  • TAGS

How to recover an error from a Future in an EssentialAction

scala,playframework,future,iteratee

Oddly enough, I thought that the problem might've been that the function wasn't inferring the proper type you needed. This has happened to me in the past where the result type depended on an existing generic type, e.g. U >: T. After trying your code snippet though, I noticed that...

How to merge 2 Enumerators in one, based on merge rule

java,scala,playframework-2.0,enumerator,iteratee

Here is a solution that will work for any number of Enumerator values using any Ordering on the elements: import play.api.libs.iteratee._ import scala.concurrent._ object MergeEnums { def apply[E: Ordering](enums: Enumerator[E]*)(implicit executor: ExecutionContext) = new Enumerator[E] { def apply[A](iter: Iteratee[E, A]) = { case class IterateeReturn(o: Option[(Promise[Promise[IterateeReturn]], E)]) val failP =...

Creating a simple Iteratee gives type error ?

scala,playframework-2.0,read-eval-print-loop,fold,iteratee

Scala's type inference isn't smart enough to say "oh, you wrote acc + ele and I know that acc is an integer, so ele must also be an integer". In context you often won't need the extra type annotation. For example, this compiles just fine: Enumerator(1, 2, 3).run(Iteratee.fold(0) { (acc,...

Understanding Concurrent.unicast's arguments

scala,websocket,playframework-2.2,iteratee

Each of these is different, but the differences are subtle. The onComplete parameter of unicast lets you setup a callback for when the Iteratee that it is applied to completes successfully. The separate onError callback is for when it fails. The onDoneEnumerating method of Enumerator lets you attach a callback...

Elegant Iteratee -> Enumerator “forwarding” in Play

scala,asynchronous,playframework-2.0,akka,iteratee

You can use Concurrent.joined: val (iteratee, enumerator) = Concurrent.joined[Array[Byte]] ...

How can I create an infinite Enumerator with play iteratees

scala,playframework,iteratee

AHA! answering my own question Thanks to both @travis and @cmbaxter to pointing me into good directions. I was looking at both old source code and old api docs and didn't see newer methods like repeat. The ticket for me is unfold: scala> val s: Stream[String] = "A" #:: "B"...

Find difference between two enumerators with sorted entries in scala

scala,playframework,enumerator,iteratee

I had somewhat similar question How to merge 2 Enumerators in one, based on merge rule I modified given answer, to fit your needs object Disjunction { def disjunction[E: Ordering](enumA: Enumerator[E], enumB: Enumerator[E])(implicit ec: ExecutionContext) = new Enumerator[E] { def apply[A](iter: Iteratee[E, A]) = { case class IterateeReturn(o: Option[(Promise[Promise[IterateeReturn]], E)])...

Play / Logging / Print Response Body / Run over enumerator / buffer the body

scala,logging,playframework,enumerator,iteratee

This code works: object AccessLoggingAction extends ActionBuilder[Request] { def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = { val start = System.currentTimeMillis Logger.info(s"""Request: id=${request.id} method=${request.method} uri=${request.uri} remote-address=${request.remoteAddress} body=${request.body} """) val resultFut = block(request) resultFut.map {result => val time = System.currentTimeMillis - start Result(result.header, result.body &> Enumeratee.map(arrOfBytes => { val body =...

efficiently iterate over the not set values in a massive bit array in Java

java,bitarray,iteratee

How can I efficiently iterate over this bit array? One way to do this is to use a BitSet. This will both scan a long[] examining 64-bits at a time but it's underlying methods are turned into intrinsics. i.e. single machine code instructions which are likely to be faster...