#FEATURE by cg
class: DelayedValue
added:
#valueOnTimeout:do:
#valueWithTimeout:
comment/format in: #value
--- a/DelayedValue.st Tue Jun 25 14:28:51 2019 +0200
+++ b/DelayedValue.st Tue Jun 25 17:19:41 2019 +0200
@@ -216,13 +216,45 @@
|sema|
(sema := semaphore) notNil ifTrue:[
- sema waitUncounted. "Wait for evaluation to complete"
- "(if not already completed)"
+ "Wait for evaluation to complete (if not already completed)"
+ sema waitUncounted.
].
^ result
"Created: / 04-10-2011 / 17:36:06 / cg"
- "Modified (comment): / 25-06-2019 / 07:53:28 / Claus Gittinger"
+ "Modified (comment): / 25-06-2019 / 17:17:47 / Claus Gittinger"
+!
+
+valueOnTimeout:secondsOrNilOrTimeDuration do:exceptionalValue
+ "retrieve the value, possibly waiting for the result to arrive;
+ if a timeout happens, return the value from exceptionalValue."
+
+ |sema|
+
+ (sema := semaphore) notNil ifTrue:[
+ "Wait for evaluation to complete (if not already completed)"
+ (sema waitUncountedWithTimeout:secondsOrNilOrTimeDuration) isNil ifTrue:[
+ ^ exceptionalValue value
+ ].
+ ].
+ ^ result
+
+ "Created: / 25-06-2019 / 17:19:30 / Claus Gittinger"
+!
+
+valueWithTimeout:secondsOrNilOrTimeDuration
+ "retrieve the value, possibly waiting for the result to arrive;
+ if a timeout happens, return nil."
+
+ |sema|
+
+ (sema := semaphore) notNil ifTrue:[
+ "Wait for evaluation to complete (if not already completed)"
+ sema waitUncountedWithTimeout:secondsOrNilOrTimeDuration.
+ ].
+ ^ result
+
+ "Created: / 25-06-2019 / 17:17:34 / Claus Gittinger"
! !
!DelayedValue methodsFor:'testing'!