9
|
1 |
'From Smalltalk/X, Version:2.7.3 on 31-oct-1993 at 23:49:46'!
|
|
2 |
|
|
3 |
Object subclass:#Delay
|
|
4 |
instanceVariableNames:'milliseconds'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Kernel-Processes'
|
|
8 |
!
|
|
9 |
|
|
10 |
!Delay class methodsFor:'instance creation'!
|
|
11 |
|
|
12 |
forMilliseconds:millis
|
|
13 |
^ self new milliseconds:millis
|
|
14 |
!
|
|
15 |
|
|
16 |
forSeconds:seconds
|
|
17 |
^ self new milliseconds:(seconds * 1000)
|
|
18 |
! !
|
|
19 |
|
|
20 |
!Delay methodsFor:'accessing'!
|
|
21 |
|
|
22 |
milliseconds:aNumber
|
|
23 |
milliseconds := aNumber
|
|
24 |
! !
|
|
25 |
|
|
26 |
!Delay methodsFor:'delaying'!
|
|
27 |
|
|
28 |
wait
|
|
29 |
"suspend the current process"
|
|
30 |
|
|
31 |
|sema|
|
|
32 |
|
|
33 |
sema := Semaphore new.
|
14
|
34 |
Processor currentProcess state:#timeWait.
|
9
|
35 |
Processor enableSemaphore:sema afterMilliseconds:milliseconds.
|
|
36 |
sema wait
|
|
37 |
|
|
38 |
"'1' printNewline.
|
|
39 |
(Delay forSeconds:10) wait.
|
|
40 |
'2' printNewline
|
|
41 |
"
|
|
42 |
! !
|