Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 632
Gakuo Avatar asked Apr 18 '18 23:04

Gakuo


1 Answers

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.

like image 160
Leandro Caniglia Avatar answered Nov 07 '22 06:11

Leandro Caniglia