Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from volgar1x/NetworkComponent.scala
Last active December 27, 2015 06:09
Show Gist options
  • Save vendethiel/7279621 to your computer and use it in GitHub Desktop.
Save vendethiel/7279621 to your computer and use it in GitHub Desktop.
type Transaction = mutable.Builder[Any, _]
def transaction[R](fn: Transaction => R): Future[NetworkSession] = {
val builder = List.newBuilder[Any]
fn(builder)
@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), builder.result()) flatMap {_.flush()}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment