2

I have a do: in Pharo that takes a long time to process. I'd like to show the progress of it to the user. How is that done in Pharo?

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
  • Dear down voter who left no comment: how is this question worse than https://stackoverflow.com/questions/3951903 or https://stackoverflow.com/q/238073/1168342 or https://stackoverflow.com/q/3160699/1168342 – Fuhrmanator Nov 19 '18 at 15:31

1 Answers1

8

Here are two ways:

  1. Collection borrows from UIManager and supports a displayingProgress: every: milliseconds variant of do::

    (1 to: 60)
       do: [ :e | (Delay forSeconds: 0.5) wait "simulate a delay" ]
       displayingProgress: [ :e | 'waiting ' , e asString ] every: 1000
    

    You can play with the every: on this example to see that if you set it to less than 1000ms, it will update more often (setting it to 100 will show you every value of the interval).

    Also, you can simply use displayingProgress: 'Waiting...' to only show the same string the whole time, without a block.

  2. Using the Job class. Here's a similar solution as above:

    myColl := 1 to: 20.
    [ :job | 
    myColl
       do: [ :e | 
          job
            progress: e / myColl size;
            title: 'waiting ' , e asString.
          (Delay forSeconds: 0.5) wait ] ] asJob run
    
Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111