-
-
Save vendethiel/7279621 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 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