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