eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Promise':

Home

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

Class: Promise


Inheritance:

   Object
   |
   +--Promise
      |
      +--TimedPromise

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.19 date: 2021/01/20 12:56:04
user: cg
file: Promise.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


When created, a promise will start to evaluate its block in the background,
and promise to deliver the value of this computation, when asked
for it via #value. 
If an exception happens druing the block evaluate,
it will be delivered  to the value-consumer.

Promises can be used for background computations,
which automatically block the user of the result when that result is needed,
unless the computation finished in the meanwhile.

See also Block>>promise and Lazy/Future in libbasic2.

copyright

COPYRIGHT (c) 1993 by Claus Gittinger 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
(comment from inherited method)
return an instance of myself without indexed variables

o  value: aBlock
create and return a Promise to evaluate aBlock at the current priority

o  value: aBlock priority: aPrio
create and return a Promise to evaluate aBlock at some priority


Instance protocol:

accessing
o  value
return the value of the promise.
If the evaluation process has not yet finished, wait for it.
Otherwise return the value immediately.
Any exception which occurred during the evaluation is forwarded to the
requestor of the value here.

Usage example(s):

value is asked for.

o  value: anObject
fake value arrived

initialization
o  initialize
setup

o  value: aBlock priority: aPrio
setup and start the evaluation process.

Usage example(s):

     Promise value:[100 timesRepeat:[1000 factorial]] priority:7

Usage example(s):

     Promise value:[10 timesRepeat:[1000 factorial]. [self halt] value.] priority:7

queries
o  hasValue
return true, if the promise has a value available.
(i.e. if sending #value to it would NOT block)


Examples:


|p|

p := [10000 factorial] promise.
Transcript showCR:'doing something else'.
p value   


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:15:47 GMT