TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
Continuations in scala (incomplete version)
1. continuations in
fujohnwang
@Twitter
@weibo
Saturday, July 9, 2011
2. what’s continuation?
Continuation capture the state of a
computation(maybe to be invoked later).
Simple concept, but hard to get.
first-class support in schema language
Saturday, July 9, 2011
3. know CPS first
normal control flow structure
control flow structure after cps
PS.
code
sample
borrowed
from
http://www.slideshare.net/openbala/continuations
Saturday, July 9, 2011
11. code pieces
function calculator()
{
var a, b, operator;
cocoon.sendPageAndWait("getA.html");
a = cocoon.request.get("a");
cocoon.sendPageAndWait("getB.html");
b = cocoon.request.get("b");
cocoon.sendPageAndWait("getOperator.html");
operator = cocoon.request.get("op");
try {
if (operator == "plus")
cocoon.sendPage("result.html", {result: a + b});
else if (operator == "minus")
cocoon.sendPage("result.html", {result: a - b});
else if (operator == "multiply")
cocoon.sendPage("result.html", {result: a * b});
else if (operator == "divide")
cocoon.sendPage("result.html", {result: a / b});
else
cocoon.sendPage("invalidOperator.html", {operator: operator});
}
catch (exception) {
cocoon.sendPage("error.html", {message: "Operation failed: " + exception.toString
()});
}
Saturday,} 9, 2011
July
12. Continuation types
full continuation(aka. first-class cont.)
delimited continuation (aka. partial, composable cont.)
write async code as sequence one
mix cps code and normal code seamlessly
Saturday, July 9, 2011
14. first glance with dc
reset and shift
reset sets up the boundary of dc(‘s cps)
shift captures the continuation
Result types
yield
return
Saturday, July 9, 2011
15. puzzle about
yield and return
Saturday, July 9, 2011
16. scala cont features
compiler plugin + Library
compiler plugin does cps transformation
library supports control structures and directives
serializable (can be saved, distribute sys...)
see swarm?!
Others?
Saturday, July 9, 2011
17. available softwares
swarm
scalaflow
Akka’s DataFlow Concurrency library
nio actor implementation for akka
nioserver
Saturday, July 9, 2011
18. What I want to do with it
coroutine
combine with java nio
resource-efficient minimally-threaded
networking layer framework
reduce hw cost finally
Saturday, July 9, 2011