--- a/Future.st Wed Jan 26 14:54:57 2005 +0100
+++ b/Future.st Wed Jan 26 14:55:27 2005 +0100
@@ -65,6 +65,9 @@
[author:]
tph@cs.man.ac.uk
+
+ [see also:]
+ Block Lazy LazyValue
"
!
@@ -72,13 +75,13 @@
"
Starts evaluating the factorial immediately, but waits until
the result is available before printing the answer
- [exBegin]
+ [exBegin]
| fac |
- fac := [100 factorial] futureValue.
+ fac := [5000 factorial] futureValue.
Transcript showCR: 'evaluating factorial...'.
Transcript showCR: fac printString
- [exEnd]
+ [exEnd]
An example illustrating the use of multiple futures and
@@ -86,24 +89,24 @@
Starts evaluating both factorials immediately, but waits until
both blocks have finished before continuing.
- [exBegin]
+ [exBegin]
| fac1 fac2 |
fac1 := [Transcript showCR: 'Starting fac1.. '. 1000 factorial] futureValue.
fac2 := [Transcript showCR: 'Starting fac2.. '. 2000 factorial] futureValue.
- fac2 touch.
- fac1 touch.
+ fac2 isString.
+ fac1 isString.
Transcript showCR: 'both completed.'.
- [exEnd]
+ [exEnd]
Example showing how arguments may be passed to futures.
- [exBegin]
+ [exBegin]
| temp |
temp := [:x :y | 10 * x * y] futureValue: 3 value: 4.
Transcript showCR: temp printString.
- [exEnd]
+ [exEnd]
Claus:
The above examples do not really show the power of Futures;
@@ -113,44 +116,44 @@
Here, the input is read before - the readTime and view creation
times sum up:
- [exBegin]
- |p text v|
+ [exBegin]
+ |p text v|
- p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
- text := p contents.
- p close.
- v := TextView new openAndWait.
- v contents:text
- [exEnd]
+ p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
+ text := p contents.
+ p close.
+ v := TextView new openAndWait.
+ v contents:text
+ [exEnd]
The same here:
- [exBegin]
- |p text v|
+ [exBegin]
+ |p text v|
- v := TextView new openAndWait.
- p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
- text := p contents.
- p close.
- v contents:text
- [exEnd]
+ v := TextView new openAndWait.
+ p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
+ text := p contents.
+ p close.
+ v contents:text
+ [exEnd]
Here, the view creation and reading are done in parallel:
(if the user is slow when opening the view, the contents may
be already available)
- [exBegin]
- |p text v|
+ [exBegin]
+ |p text v|
- text := [ |p t|
+ text := [ |p t|
- p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
- t := p contents.
- p close.
- t
- ] futureValue.
- v := TextView new openAndWait.
- v contents:text
- [exEnd]
+ p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
+ t := p contents.
+ p close.
+ t
+ ] futureValue.
+ v := TextView new openAndWait.
+ v contents:text
+ [exEnd]
"
! !
@@ -240,5 +243,5 @@
!Future class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.9 2005-01-26 13:41:37 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.10 2005-01-26 13:55:27 stefan Exp $'
! !