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.7 date: 2023/06/08 13:58:50
user: cg
file: DelayedValue.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

COPYRIGHT (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.

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

private
o  onValueRequested
nothing done here, but needed in subclass

providing value
o  errorValueAlreadyProvided

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

synchronising
o  doesNotUnderstand: aMessage
(Almost) 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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 18:05:21 GMT