eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'DelayedValue':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: DelayedValue


Inheritance:

   ProtoObject
   |
   +--DelayedValue
      |
      +--Future

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.4 date: 2019/06/25 15:19:41
user: cg
file: DelayedValue.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
cg

Description:


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.


Related information:

    Block
    Lazy
    LazyValue
    Future
    Promise

Class protocol:

instance creation
o  new
return an initialized instance


Instance protocol:

initialization
o  initialize
Invoked when a new instance is created.

o  initializeSemaphore
Invoked when a new instance is created.

printing
o  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).

o  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).

providing value
o  errorValueAlreadyProvided

o  value: anyObject
value is now provided.
If anyone is waiting on me, signal the semaphore

synchronising
o  doesNotUnderstand: aMessage
Any message to a Future will end up here.

o  perform: aSelector withArguments: argArray
send the message aSelector with all args taken from argArray
to the receiver.

o  value
retrieve the value, possibly waiting for the result to arrive

o  valueOnTimeout: secondsOrNilOrTimeDuration do: exceptionalValue
retrieve the value, possibly waiting for the result to arrive;
if a timeout happens, return the value from exceptionalValue.

o  valueWithTimeout: secondsOrNilOrTimeDuration
retrieve the value, possibly waiting for the result to arrive;
if a timeout happens, return nil.

testing
o  hasValue
true if I have already a value
(i.e. would not block when sending me a message)

o  isLazyValue
true if I have no value yet
(i.e. would block when sending me a message)


Examples:


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


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Wed, 20 Jan 2021 22:41:58 GMT