Skip to content

Commit

Permalink
[twitter-server] Stream admin/events page
Browse files Browse the repository at this point in the history
Problem

The Sink exposes an iterator over Events, which we can render into an
HTML stream (we already stream for the JSON handler), but we don't do
this for the HTML admin page. Consequently, this requires the controller
to fully buffer the HTML which could be potentially large.

Solution

Incrementally render and write HTML as we iterate over Events in the
Sink.

RB_ID=608234
  • Loading branch information
luciferous authored and jenkins committed Mar 23, 2015
1 parent 50db5ce commit 000f94c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions util-core/src/main/scala/com/twitter/concurrent/Spool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ object Spool {
}
}

/**
* Lazily builds a Spool from a Seq.
*
* The main difference between this and `seqToSpool` is that this method also
* consumes the Seq lazily, which means if used with Streams, it will
* preserve laziness.
*/
def fromSeq[A](seq: Seq[A]): Spool[A] = {
def go(as: Seq[A]): Future[Spool[A]] =
if (as.isEmpty) Future.value(Spool.empty)
else Future.value(as.head *:: go(as.tail))

if (seq.isEmpty) Spool.empty else seq.head *:: go(seq.tail)
}

/**
* Adds an implicit method to efficiently convert a Seq[A] to a Spool[A]
*/
Expand Down

0 comments on commit 000f94c

Please sign in to comment.