I am trying to extend Pharo with promises/futures. I came across this website http://onsmalltalk.com/smalltalk-concurrency-playing-with-futures. It implements futures in Smalltalk. However, when I copy this part of the code onto Pharo, I get some errors:
value: aBlock
promiseLock := Semaphore new.
[ [ promiseValue := aBlock value ]
on: Error
do: [ :err | promiseError := err ]
ensure: [ promiseLock signal ] ] forkBackground
These are the errors:
[forkBackground] Messages sent but not implemented
[on:do:ensure:] Messages sent but not implemented
I was of the idea that Pharo is not different from Smalltalk, or is it possible that the website's solution does not also work with Smalltalk?
Try the following:
promiseLock := Semaphore new.
[
[[promiseValue := aBlock value] on: Error do: [:err | promiseError := err]]
ensure: [promiseLock signal]] forkAt: Processor userBackgroundPriority
The idea is to ensure:
that the promiseLock
semaphore will receive a signal
even if an Error
curtails the evaluation of aBlock
. The priority to forkAt:
is debatable, but I would start somewhere, and adjust it as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With