From 84990057c896d7652fa956afa2367c0f23e7f020 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Mon, 10 Jun 2013 17:44:07 -0400 Subject: [PATCH] Safe futures must take a spore --- sips/pending/_posts/2013-06-10-spores.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sips/pending/_posts/2013-06-10-spores.md b/sips/pending/_posts/2013-06-10-spores.md index 60c6f3effb..ced4630e9a 100644 --- a/sips/pending/_posts/2013-06-10-spores.md +++ b/sips/pending/_posts/2013-06-10-spores.md @@ -172,19 +172,22 @@ We now revisit the motivating examples we described in the above section, this t ### Futures and Akka actors +The safety of futures can be improved by requiring the body of a new +future to be a nullary spore (a spore with an empty parameter +list). + Using spores, example 1 can be re-written as follows: def receive = { case Request(data) => - val s = spore { + future(spore { val from = sender val d = data () => { val result = transform(d) from ! Response(result) } - } - future { s() } + }) } In this case, the problematic capturing of `this` is avoided, since the result of `this.sender` is assigned to the spore's local value `from` when the spore is created. The spore conformity checking ensures that within the spore's closure, only `from` and `d` are used.