Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep in Smalltalk Squeak

I'm dealing with N*N queens problem and gui of it. I want to sleep for a few seconds each move so the viewer can see the process. How do I put smalltalk to sleep?

Thank you

like image 726
Ariel Pinchover Avatar asked Nov 08 '25 00:11

Ariel Pinchover


1 Answers

Instead of sleeping you can just wait.

5 seconds asDelay wait.

e.g. if you select and print it the following, it will wait 5 seconds before printing the result (2)

[
    5 seconds asDelay wait.
    1 + 1
] value

The comment of the Delay class explains what it does.

I am the main way that a process may pause for some amount of time. The simplest usage is like this:

(Delay forSeconds: 5) wait.

An instance of Delay responds to the message 'wait' by suspending the caller's process for a certain amount of time. The duration of the pause is specified when the Delay is created with the message forMilliseconds: or forSeconds:. A Delay can be used again when the current wait has finished. For example, a clock process might repeatedly wait on a one-second Delay.

A delay in progress when an image snapshot is saved is resumed when the snapshot is re-started. Delays work across millisecond clock roll-overs.

For a more complex example, see #testDelayOf:for:rect: .

Update: (based on comment)

wait will pause the execution flow, which means that in the example earlier, the 1 + 1 will get executed (execution flow resumed) only after the wait period has ended.

So in your class you can have...

MyBoard>>doStep
    self drawBoard.
    5 seconds asDelay wait.
    self solve.
    5 seconds asDelay wait.
    self destroyBoard.
like image 125
Peter Uhnak Avatar answered Nov 09 '25 19:11

Peter Uhnak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!