|
Class: DelayedValue
ProtoObject
|
+--DelayedValue
|
+--Future
- Package:
- stx:libbasic2
- Category:
- Kernel-Processes
- Version:
- rev:
1.7
date: 2023/06/08 13:58:50
- user: cg
- file: DelayedValue.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
I am similar to a Future, in that I represent an execution in progress,
whose value will be required some time in the future.
In contrast to a future, which itself spawns a thread to perform the computation,
my value comes from an external source (typically, an event or incoming message from an
interprocess communication channel).
In contrast to a Promise, instances of me can be used interchangable with the promised value
(i.e. I will catch DNU, wait for the value and forward the message automatically)
I will delay any messages sent to me, until the execution has completed (i.e. the value was provided).
This is useful to return values from external sources (print jobs, compile jobs etc.),
which can be done in the background and the user can do something else
in the meantime.
If the computation is finished before the user needs its value, he is not forced to wait.
If the computation is unfinished, he has to wait for the remaining time only.
copyrightCOPYRIGHT (c) 2019 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
new
-
return an initialized instance
initialization
-
initialize
-
Invoked when a new instance is created.
-
initializeSemaphore
-
Invoked when a new instance is created.
printing
-
displayOn: aGCOrStream
-
notice: displayString and displayOn: will not wait for the value (they are for developers and inspectors),
whereas printString and printOn: will wait (they are for the program to print data).
-
displayString
-
notice: displayString and displayOn: will not wait for the value (they are for developers and inspectors),
whereas printString and printOn: will wait (they are for the program to print data).
private
-
onValueRequested
-
nothing done here, but needed in subclass
providing value
-
errorValueAlreadyProvided
-
-
value: anyObject
-
value is now provided.
If anyone is waiting on me, signal the semaphore
synchronising
-
doesNotUnderstand: aMessage
-
(Almost) any message to a Future will end up here.
-
perform: aSelector withArguments: argArray
-
send the message aSelector with all args taken from argArray
to the receiver.
-
value
-
retrieve the value, possibly waiting for the result to arrive
-
valueOnTimeout: secondsOrNilOrTimeDuration do: exceptionalValue
-
retrieve the value, possibly waiting for the result to arrive;
if a timeout happens, return the value from exceptionalValue.
-
valueWithTimeout: secondsOrNilOrTimeDuration
-
retrieve the value, possibly waiting for the result to arrive;
if a timeout happens, return nil.
testing
-
hasValue
-
true if I have already a value
(i.e. would not block when sending me a message)
-
isLazyValue
-
true if I have no value yet
(i.e. would block when sending me a message)
Waits for someon else to provide a value after some time-consuming computation
(could be a remote process, sending me an event):
| delayedValue |
delayedValue := DelayedValue new.
[
Transcript showCR: 'evaluating factorial...'.
Delay waitForSeconds:2.
delayedValue value:(100 factorial).
Transcript showCR: 'done...'.
] fork.
Transcript showCR:'The value is: %1' with:delayedValue
|
|