diff options
author | Philipp Haller <hallerp@gmail.com> | 2013-05-23 15:52:31 +0200 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2013-05-23 15:52:31 +0200 |
commit | 8b740b436a3de111269e004e595fda70f6533704 (patch) | |
tree | 41ec001a0e5eb72940d0c32473121775d3220d8a /src/main/scala/scala/async/Async.scala | |
parent | ffab92802c130c7e881440d360e7cef051b7f3d4 (diff) | |
download | scala-async-topic/wip-futuresystem-extension.tar.gz scala-async-topic/wip-futuresystem-extension.tar.bz2 scala-async-topic/wip-futuresystem-extension.zip |
Enable generalized state machinestopic/wip-futuresystem-extension
- async { } block can now generate a subclass of an existing trait
- future system can directly return the state machine instance
from async, without spawning an actual future
- adds iterator-based async implementation with future system
Diffstat (limited to 'src/main/scala/scala/async/Async.scala')
-rw-r--r-- | src/main/scala/scala/async/Async.scala | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala index c480b62..ed0f0ef 100644 --- a/src/main/scala/scala/async/Async.scala +++ b/src/main/scala/scala/async/Async.scala @@ -118,7 +118,8 @@ abstract class AsyncBase { lazy val stateMachine: ClassDef = { val body: List[Tree] = { val stateVar = ValDef(Modifiers(Flag.MUTABLE), name.state, TypeTree(definitions.IntTpe), Literal(Constant(0))) - val result = ValDef(NoMods, name.result, TypeTree(futureSystemOps.promType[T]), futureSystemOps.createProm[T].tree) + val result = + ValDef(NoMods, name.result, TypeTree(futureSystemOps.promType[T]), futureSystemOps.createPromTree[T](Ident(name.stateMachine))) val execContext = ValDef(NoMods, name.execContext, TypeTree(), futureSystemOps.execContext.tree) val applyDefDef: DefDef = { val applyVParamss = List(List(ValDef(Modifiers(Flag.PARAM), name.tr, TypeTree(futureSystemOps.resultType[Any]), EmptyTree))) @@ -145,16 +146,13 @@ abstract class AsyncBase { val code: c.Expr[futureSystem.Fut[T]] = { val isSimple = asyncStates.size == 1 val tree = - if (isSimple) - Block(Nil, futureSystemOps.spawn(body.tree)) // generate lean code for the simple case of `async { 1 + 1 }` - else { - Block(List[Tree]( + Block( + List[Tree]( stateMachine, ValDef(NoMods, name.stateMachine, TypeTree(stateMachineType), Apply(Select(New(Ident(name.stateMachineT)), nme.CONSTRUCTOR), Nil)), - futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil)) + futureSystemOps.spawn(Ident(name.stateMachine)) ), futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree) - } c.Expr[futureSystem.Fut[T]](tree) } |