[英]Sleep in Smalltalk Squeak
I'm dealing with N*N queens problem and gui of it. 我正在处理N * N个皇后问题及其gui。 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 谢谢
Instead of sleeping you can just wait. 不用睡觉,您可以等待。
5 seconds asDelay wait.
eg if you select and print it the following, it will wait 5 seconds before printing the result (2) 例如,如果您选择并打印以下内容,它将等待5秒钟再打印结果(2)
[
5 seconds asDelay wait.
1 + 1
] value
The comment of the Delay
class explains what it does. Delay
类的注释说明了它的作用。
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. (延迟时间:5)等待。
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:. 在创建延迟时,使用消息forMilliseconds:或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: . 有关更复杂的示例,请参见#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. wait
将暂停执行流程,这意味着在前面的示例中,只有在等待时间段结束之后,才会执行1 + 1
(恢复执行流程)。
So in your class you can have... 因此,您可以在课堂上...
MyBoard>>doStep
self drawBoard.
5 seconds asDelay wait.
self solve.
5 seconds asDelay wait.
self destroyBoard.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.