65 |
66 |
66 examples |
67 examples |
67 " |
68 " |
68 Check your systems resolution with: |
69 Check your systems resolution with: |
69 (make certain, that no other timed processes are running in the background when doing this) |
70 (make certain, that no other timed processes are running in the background when doing this) |
70 |
71 [exBegin] |
71 |d t1 t2 res| |
72 |d t1 t2 res| |
72 |
73 |
73 Processor activeProcess priority:24. |
74 Processor activeProcess priority:24. |
74 t1 := Time millisecondClockValue. |
75 t1 := Time millisecondClockValue. |
75 d := Delay forMilliseconds:1. |
76 d := Delay forMilliseconds:1. |
76 100 timesRepeat:[d wait]. |
77 100 timesRepeat:[d wait]. |
77 t2 := Time millisecondClockValue. |
78 t2 := Time millisecondClockValue. |
78 res := (OperatingSystem millisecondTimeDeltaBetween:t2 and:t1) // 100. |
79 res := (OperatingSystem millisecondTimeDeltaBetween:t2 and:t1) // 100. |
79 Transcript show:'minimum delta is about '; show:res; showCr:' milliseconds'. |
80 Transcript show:'minimum delta is about '; show:res; showCr:' milliseconds'. |
80 Processor activeProcess priority:8. |
81 Processor activeProcess priority:8. |
|
82 [exEnd] |
81 |
83 |
82 |
84 |
83 examples: |
85 examples: |
84 |
86 |
85 delaying for some time-delta: |
87 delaying for some time-delta: |
86 (notice: you cannot use this without time-errors in a loop, |
88 (notice: you cannot use this without time-errors in a loop, |
87 since the errors will accumulate; after 5 runs through the loop, |
89 since the errors will accumulate; after 5 runs through the loop, |
88 more than 5 seconds have passed) |
90 more than 5 seconds have passed) |
89 |
91 |
90 |d| |
92 |d| |
91 d := Delay forMilliseconds:500. |
93 d := Delay forMilliseconds:500. |
92 10 timesRepeat:[d wait] |
94 10 timesRepeat:[d wait] |
93 |
95 |
94 prove: |
96 prove: |
95 |d t1 t2 deltaT| |
97 [exBegin] |
96 d := Delay forMilliseconds:500. |
98 |d t1 t2 deltaT| |
97 t1 := Time millisecondClockValue. |
99 d := Delay forMilliseconds:500. |
98 10 timesRepeat:[ |
100 t1 := Time millisecondClockValue. |
99 d wait |
101 10 timesRepeat:[ |
100 ]. |
102 d wait |
101 t2 := Time millisecondClockValue. |
103 ]. |
102 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
104 t2 := Time millisecondClockValue. |
103 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
105 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
104 |
106 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
105 delaying until a specific time is reached: |
107 [exEnd] |
106 (this can be used to fix the above problem) |
108 |
107 |
109 delaying until a specific time is reached: |
108 |now then t1 t2 deltaT| |
110 (this can be used to fix the above problem) |
109 |
111 [exBegin] |
110 t1 := Time millisecondClockValue. |
112 |now then t1 t2 deltaT| |
111 now := Time millisecondClockValue. |
113 |
112 10 timesRepeat:[ |
114 t1 := Time millisecondClockValue. |
113 then := OperatingSystem millisecondTimeAdd:now and:1000. |
115 now := Time millisecondClockValue. |
114 (Delay untilMilliseconds:then) wait. |
116 10 timesRepeat:[ |
115 now := then |
117 then := OperatingSystem millisecondTimeAdd:now and:1000. |
116 ]. |
118 (Delay untilMilliseconds:then) wait. |
117 t2 := Time millisecondClockValue. |
119 now := then |
118 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
120 ]. |
119 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
121 t2 := Time millisecondClockValue. |
120 |
122 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
121 instead of recreating new delays, you can also reuse it: |
123 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
122 |
124 [exEnd] |
123 |d now then t1 t2 deltaT| |
125 |
124 |
126 instead of recreating new delays all over, |
125 t1 := Time millisecondClockValue. |
127 you can also reuse it: |
126 now := Time millisecondClockValue. |
128 [exBegin] |
127 d := Delay new. |
129 |d now then t1 t2 deltaT| |
128 10 timesRepeat:[ |
130 |
129 then := OperatingSystem millisecondTimeAdd:now and:1000. |
131 t1 := Time millisecondClockValue. |
130 d resumtionTime:then. |
132 now := Time millisecondClockValue. |
131 d wait. |
133 d := Delay new. |
132 now := then |
134 10 timesRepeat:[ |
133 ]. |
135 then := OperatingSystem millisecondTimeAdd:now and:1000. |
134 t2 := Time millisecondClockValue. |
136 d resumtionTime:then. |
135 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
137 d wait. |
136 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
138 now := then |
|
139 ]. |
|
140 t2 := Time millisecondClockValue. |
|
141 deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1. |
|
142 Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds' |
|
143 [exEnd] |
137 " |
144 " |
138 ! ! |
145 ! ! |
139 |
146 |
140 !Delay class methodsFor:'instance creation'! |
147 !Delay class methodsFor:'instance creation'! |
141 |
148 |