Created
November 2, 2013 14:43
-
-
Save volgar1x/7279594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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