1522
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
1487
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
4631
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
1487
|
16 |
Promise subclass:#TimedPromise
|
|
17 |
instanceVariableNames:'delay ms'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Kernel-Processes'
|
|
21 |
!
|
|
22 |
|
|
23 |
!TimedPromise class methodsFor:'documentation'!
|
|
24 |
|
1522
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
1487
|
39 |
documentation
|
|
40 |
"
|
|
41 |
A TimedPromise is a Promise with a timeout.
|
|
42 |
An attempt to read the value of a TimedPromise will wait until the process has finished computing it
|
|
43 |
or the specified timeout expires.
|
|
44 |
If the process terminates with an exception, an attempt to read the value of the TimedPromise will raise the same exception.
|
|
45 |
In case of a timeout the OsNeedRetryError will be raised.
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
examples
|
|
50 |
"
|
|
51 |
[exBegin]
|
|
52 |
|p|
|
|
53 |
|
|
54 |
p := TimedPromise forMilliseconds:1000.
|
|
55 |
p value:[10000 factorial] priority:Processor activePriority.
|
|
56 |
|
|
57 |
Transcript showCR:'doing something else'.
|
|
58 |
p value
|
|
59 |
[exEnd]
|
|
60 |
|
|
61 |
|
|
62 |
[exBegin]
|
|
63 |
|p|
|
|
64 |
|
|
65 |
p := TimedPromise forMilliseconds:1000.
|
|
66 |
p value:[1000 factorial] priority:Processor activePriority.
|
|
67 |
|
|
68 |
Transcript showCR:'doing something else'.
|
|
69 |
p value
|
|
70 |
[exEnd]
|
|
71 |
|
|
72 |
|
|
73 |
[exBegin]
|
|
74 |
|p|
|
|
75 |
|
|
76 |
p := TimedPromise forMilliseconds:1000.
|
|
77 |
p value:[1000 factorial. ZeroDivide raise] priority:Processor activePriority.
|
|
78 |
|
|
79 |
Transcript showCR:'doing something else'.
|
|
80 |
p value
|
|
81 |
[exEnd]
|
|
82 |
"
|
|
83 |
! !
|
|
84 |
|
|
85 |
!TimedPromise class methodsFor:'instance creation'!
|
|
86 |
|
|
87 |
forMilliseconds: ms
|
|
88 |
^super new ms: ms.
|
|
89 |
! !
|
|
90 |
|
|
91 |
!TimedPromise methodsFor:'accessing'!
|
|
92 |
|
|
93 |
ms: msec
|
|
94 |
ms := msec
|
|
95 |
! !
|
|
96 |
|
|
97 |
!TimedPromise methodsFor:'accessing-parent'!
|
|
98 |
|
|
99 |
value
|
|
100 |
| whichSemaSignalled delaySemaphore |
|
|
101 |
|
|
102 |
" Note -- only good for one waiter "
|
|
103 |
delay notNil ifTrue:[
|
|
104 |
self error:'Only one waiter allowed'.
|
|
105 |
].
|
|
106 |
|
|
107 |
self startup.
|
|
108 |
delay isNil ifTrue: [ ^ super value ].
|
|
109 |
|
|
110 |
delaySemaphore := delay delaySemaphore.
|
|
111 |
whichSemaSignalled := (SemaphoreSet with:valueAvailable with:delaySemaphore) wait.
|
|
112 |
delay disable.
|
|
113 |
delay := nil.
|
|
114 |
|
|
115 |
exception == nil
|
|
116 |
ifTrue: [
|
|
117 |
whichSemaSignalled == delaySemaphore
|
|
118 |
ifTrue: [OSErrorHolder needRetrySignal raise]
|
|
119 |
ifFalse: [^value]]
|
|
120 |
ifFalse: [exception raise "(exception copyForReraise) searchFrom: thisContext; raise"]
|
|
121 |
! !
|
|
122 |
|
|
123 |
!TimedPromise methodsFor:'private'!
|
|
124 |
|
|
125 |
startup
|
3187
|
126 |
"Wait for data arrival or alarm expiry."
|
|
127 |
|
4631
|
128 |
ms notNil ifTrue:[delay := Delay forMilliseconds:ms]
|
|
129 |
|
|
130 |
"Modified: / 10-04-2018 / 09:49:01 / stefan"
|
1487
|
131 |
! !
|
|
132 |
|
|
133 |
!TimedPromise class methodsFor:'documentation'!
|
|
134 |
|
|
135 |
version
|
4631
|
136 |
^ '$Header$'
|
1487
|
137 |
! !
|
3187
|
138 |
|