--- a/Future.st Thu Jan 16 14:04:49 1997 +0100
+++ b/Future.st Thu Jan 16 14:45:49 1997 +0100
@@ -43,6 +43,130 @@
execution has completed.'
!
+!Future class methodsFor:'documentation'!
+
+copyright
+"
+ This is a Manchester Goodie protected by copyright.
+ These conditions are imposed on the whole Goodie, and on any significant
+ part of it which is separately transmitted or stored:
+ * You must ensure that every copy includes this notice, and that
+ source and author(s) of the material are acknowledged.
+ * These conditions must be imposed on anyone who receives a copy.
+ * The material shall not be used for commercial gain without the prior
+ written consent of the author(s).
+ Further information on the copyright conditions may be obtained by
+ sending electronic mail:
+ To: goodies-lib@cs.man.ac.uk
+ Subject: copyright
+ or by writing to The Smalltalk Goodies Library Manager, Dept of
+ Computer Science, The University, Manchester M13 9PL, UK
+
+ (C) Copyright 1992 University of Manchester
+ For more information about the Manchester Goodies Library (from which
+ this file was distributed) send e-mail:
+ To: goodies-lib@cs.man.ac.uk
+ Subject: help
+"
+!
+
+documentation
+"
+ I represent an execution in progress.
+ Any messages sent to me are delayed until execution has completed.'
+"
+!
+
+examples
+"
+ Starts evaluating the factorial immediately, but waits until
+ the result is available before printing the answer
+ [exBegin]
+ | fac |
+
+ fac := [100 factorial] futureValue.
+ Transcript showCR: 'evaluating factorial...'.
+ Transcript showCR: fac printString
+ [exEnd]
+
+
+ An example illustrating the use of multiple futures and
+ explicit resynchronisation.
+
+ Starts evaluating both factorials immediately, but waits until
+ both blocks have finished before continuing.
+ [exBegin]
+ | fac1 fac2 |
+
+ fac1 := [Transcript showCR: 'Starting fac1.. '. 1000 factorial] futureValue.
+ fac2 := [Transcript showCR: 'Starting fac2.. '. 2000 factorial] futureValue.
+ fac2 touch.
+ fac1 touch.
+ Transcript showCR: 'both completed.'.
+ [exEnd]
+
+ Example showing how arguments may be passed to futures.
+ [exBegin]
+ | temp |
+
+ temp := [:x :y | 10 * x * y] futureValue: 3 value: 4.
+ Transcript showCR: temp printString.
+
+ [exEnd]
+
+ Claus:
+ The above examples do not really show the power of Futures;
+ they can be useful, whenever some long-time computation is
+ to be done, and some other useful work can be done in the meanwhile.
+ for example:
+
+ Here, the input is read before - the readTime and view creation
+ times sum up:
+ [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]
+
+ The same here:
+ [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]
+
+
+ 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|
+
+ 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]
+"
+!
+
+version
+ ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.5 1997-01-16 13:45:49 cg Exp $'
+! !
+
!Future methodsFor: 'synchronising'!
doesNotUnderstand: aMessage
@@ -105,47 +229,6 @@
semaphore signal] fork
! !
-!Future class methodsFor: 'examples'!
-
-example1
- "Starts evaluating the factorial immediately, but waits until
- the result is available before printing the answer!!"
-
- | fac |
- fac := [100 factorial] futureValue.
- Transcript showCR: 'evaluating factorial...'.
- Transcript showCR: fac printString
-
- "Future example1"
-!
-
-example2
- "An example illustrating the use of multiple futures and
- explicit resynchronisation."
-
- "Starts evaluating both factorials immediately, but waits until
- both blocks have finished before continuing."
-
- | fac1 fac2 |
- fac1 := [Transcript showCR: 'Starting fac1.. '. 1000 factorial] futureValue.
- fac2 := [Transcript showCR: 'Starting fac2.. '. 2000 factorial] futureValue.
- fac2 touch.
- fac1 touch.
- Transcript showCR: 'both completed.'.
-
- "Future example2"
-!
-
-example3
- "Example showing how arguments may be passed to futures."
-
- | temp |
- temp := [:x :y | 10 * x * y] futureValue: 3 value: 4.
- Transcript showCR: temp printString.
-
- "Future example3"
-! !
-
!Future class methodsFor: 'class initialization'!
initialize