我正在Pharo中实现futures。我发现了这个网站:http://onsmalltalk.com/smalltalk-concurrency-playing-with-futures。我在跟随这个例子并试图在Pharo上复制它。然而,当我到达最后一步时,我不知道">>"是什么意思:这个符号也没有作为Smalltalk语法的一部分包含在http://rigaux.org/language-study/syntax-across-languages-per-language/Smalltalk.html中。
我注意到`future`不是由`BlockClosure`实现的变量或方法。为了使承诺/未来按照http://onsmalltalk.com/smalltalk-concurrency-playing-with-futures中所示的功能工作,您需要怎么做?如果我直接将代码添加到我的Promise类中,就像它现在这样,或者我错过了什么?
在将`future`方法添加到`BlockClosure`之后,这是我尝试在PlayGround上运行的代码。
转录显示的是以下错误,而不是预期的值12。
BlockClosure>>future
^ SFuture new value: self fixTemps
我注意到`future`不是由`BlockClosure`实现的变量或方法。为了使承诺/未来按照http://onsmalltalk.com/smalltalk-concurrency-playing-with-futures中所示的功能工作,您需要怎么做?如果我直接将代码添加到我的Promise类中,就像它现在这样,或者我错过了什么?
在将`future`方法添加到`BlockClosure`之后,这是我尝试在PlayGround上运行的代码。
value1 := [200 timesRepeat:[Transcript show: '.']. 6] future.
value2 := [200 timesRepeat:[Transcript show: '+']. 6] future.
Transcript show: 'other work'.
Transcript show: (value1 + value2).
Date today
转录显示的是以下错误,而不是预期的值12。
UndefinedObject>>DoIt (value1 is Undeclared)
UndefinedObject>>DoIt (value2 is Undeclared)
fixTemps
。只需将self
作为参数发送即可。 - Leandro Canigliavalue1
和value2
被定义为SFuture
的实例,因此如果您评估这些表达式,这些变量将被声明。如果您得到它们未声明的结果,则意味着您尚未评估这些赋值语句。至少,在没有看到您正在做什么的情况下,这是我能想象到的唯一可能性。 - Leandro Caniglia