睡在 Smalltalk Squeak 中
Sleep in Smalltalk Squeak
我正在处理 N*N 皇后问题及其图形用户界面。
我想每次移动都睡几秒钟,这样观众就可以看到这个过程。
如何让 smalltalk 休眠?
谢谢
与其睡觉,你可以等待。
5 seconds asDelay wait.
例如如果您 select 和 打印它 以下内容,它将等待 5 秒然后打印结果 (2)
[
5 seconds asDelay wait.
1 + 1
] value
Delay
class 的评论解释了它的作用。
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: .
更新:(基于评论)
wait
将暂停执行流程,这意味着在前面的示例中,1 + 1
只有在等待期结束后才会执行(执行流程恢复)。
所以在你的 class 你可以有...
MyBoard>>doStep
self drawBoard.
5 seconds asDelay wait.
self solve.
5 seconds asDelay wait.
self destroyBoard.
我正在处理 N*N 皇后问题及其图形用户界面。 我想每次移动都睡几秒钟,这样观众就可以看到这个过程。 如何让 smalltalk 休眠?
谢谢
与其睡觉,你可以等待。
5 seconds asDelay wait.
例如如果您 select 和 打印它 以下内容,它将等待 5 秒然后打印结果 (2)
[
5 seconds asDelay wait.
1 + 1
] value
Delay
class 的评论解释了它的作用。
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: .
更新:(基于评论)
wait
将暂停执行流程,这意味着在前面的示例中,1 + 1
只有在等待期结束后才会执行(执行流程恢复)。
所以在你的 class 你可以有...
MyBoard>>doStep
self drawBoard.
5 seconds asDelay wait.
self solve.
5 seconds asDelay wait.
self destroyBoard.