changed:
authorStefan Vogel <sv@exept.de>
Fri, 19 Oct 2012 13:36:05 +0200
changeset 2829 e84f89563562
parent 2828 8894852ab900
child 2830 b69f6dc901f0
changed: #hasValue #isLazyValue
Future.st
--- a/Future.st	Thu Oct 18 15:36:51 2012 +0200
+++ b/Future.st	Fri Oct 19 13:36:05 2012 +0200
@@ -74,13 +74,13 @@
 "
   Starts evaluating the factorial immediately, but waits until
   the result is available before printing the answer
-								    [exBegin]
+                                                                    [exBegin]
     | fac |
 
     fac := [5000 factorial] futureValue.
     Transcript showCR: 'evaluating factorial...'.
-    Transcript showCR: fac printString
-								    [exEnd]
+    Transcript showCR: fac
+                                                                    [exEnd]
 
 
   An example illustrating the use of multiple futures and
@@ -88,7 +88,7 @@
 
   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.
@@ -96,16 +96,16 @@
     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.
+    Transcript  showCR: temp.
 
-								    [exEnd]
+                                                                    [exEnd]
 
   Claus:
     The above examples do not really show the power of Futures;
@@ -115,44 +115,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]
 "
 ! !
 
@@ -339,21 +339,21 @@
 !Future methodsFor:'testing'!
 
 hasValue
-    ^ result notNil and:[ semaphore wouldBlock not ]
+    ^ result notNil or:[semaphore wouldBlock not]
 
     "Modified: / 04-10-2011 / 17:29:36 / cg"
 !
 
 isLazyValue
-    ^ semaphore isNil or:[semaphore wouldBlock]
+    ^ result isNil and:[semaphore isNil or:[semaphore wouldBlock]]
 ! !
 
 !Future class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.16 2012-10-18 13:36:51 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.17 2012-10-19 11:36:05 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.16 2012-10-18 13:36:51 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.17 2012-10-19 11:36:05 stefan Exp $'
 ! !