promisefuturesmalltalkpharo

Pharo differences with Smalltalk


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?


Solution

  • 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.