Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created November 2, 2013 14:43
Show Gist options
  • Save volgar1x/7279594 to your computer and use it in GitHub Desktop.
Save volgar1x/7279594 to your computer and use it in GitHub Desktop.
type Transaction = mutable.Builder[Any, _]
def transaction[R](fn: Transaction => R): Future[NetworkSession] = {
val buf = List.newBuilder[Any]
fn(buf)
@tailrec
def rec(fut: Future[NetworkSession], buf: List[Any]): Future[NetworkSession] = buf match {
case head :: tail => rec(fut.flatMap(_.write(head)), tail)
case Nil => fut
}
rec(Future(this), buf.result()).flatMap(_.flush())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment