QuerySignal.st
changeset 2893 8ba406da6b22
parent 2729 184013fb5dfd
child 2900 2153bcddc299
--- a/QuerySignal.st	Thu Aug 28 04:44:08 1997 +0200
+++ b/QuerySignal.st	Tue Sep 02 19:40:57 1997 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:3.1.9 on 31-aug-1997 at 8:06:37 pm'                  !
+
 Signal subclass:#QuerySignal
 	instanceVariableNames:''
 	classVariableNames:''
@@ -231,6 +233,42 @@
 "
 ! !
 
+!QuerySignal methodsFor:'answering queries'!
+
+answer:someAnswer do:aBlock
+     "evaluate the argument, aBlock.
+      If the receiver is queried during evaluation, answer with someAnswer.
+      This is a wrapper for #handle:do: for lazy typists; no new functionality."
+
+      ^ self handle:[:ex | ex proceedWith:someAnswer] do:aBlock.
+
+      "
+       |q|
+
+       q := QuerySignal new.
+
+       q answer:true do:[
+          Transcript showCR:'query answers: ' , (q raise printString).
+       ]
+      "
+
+      "
+       |q|
+
+       q := QuerySignal new.
+
+       q answer:false do:[
+          Transcript showCR:'first query answers: ' , (q raise printString).
+          q answer:true do:[
+              Transcript showCR:'second query answers: ' , (q raise printString).
+          ]
+       ]
+      "
+
+    "Created: 10.7.1996 / 15:08:20 / cg"
+    "Modified: 14.10.1996 / 16:59:18 / cg"
+! !
+
 !QuerySignal methodsFor:'initialization'!
 
 defaultAnswer:someValue
@@ -305,46 +343,50 @@
     ^ true
 
     "Modified: 22.4.1996 / 13:45:10 / cg"
-! !
-
-!QuerySignal methodsFor:'save evaluation'!
+!
 
-answer:someAnswer do:aBlock
-     "evaluate the argument, aBlock.
-      If the receiver is queried during evaluation, answer with someAnswer.
-      This is a wrapper for #handle:do: for lazy typists; no new functionality."
+raise
+    "raise the query - return the handlers value, or the default
+     value, if there is no handler.
+     This is exactly the functionality of my inherited method,
+     but we can do it faster here."
 
-      ^ self handle:[:ex | ex proceedWith:someAnswer] do:aBlock.
-
-      "
-       |q|
-
-       q := QuerySignal new.
+    |con|
 
-       q answer:true do:[
-          Transcript showCR:'query answers: ' , (q raise printString).
-       ]
-      "
-
-      "
-       |q|
-
-       q := QuerySignal new.
+    con := thisContext sender.
+    [con notNil] whileTrue:[
+        con := con findNextContextWithSelector:#doRaise 
+                                            or:#handle:do:
+                                            or:#handle:from:do:.
+        con notNil ifTrue:[
+            (con selector == #handle:do:) ifFalse:[
+                ^ super raise
+            ].
+            (con receiver == self) ifTrue:[
+                "/ found a non-busy handler ...
+                "/ if its sender is a #answer context,
+                "/ fetch its value quickly from it.
+                con := con sender.
+                con selector == #answer:do: ifFalse:[
+                    con receiver == self ifFalse:[
+                        ^ super raise
+                    ]
+                ].
+                ^ con argAt:1
+            ]
+        ]
+    ].
+    "/ no handler found - return the default value
+    handlerBlock isNil ifTrue:[
+        ^ nil
+    ].
+    ^ super raise
 
-       q answer:false do:[
-          Transcript showCR:'first query answers: ' , (q raise printString).
-          q answer:true do:[
-              Transcript showCR:'second query answers: ' , (q raise printString).
-          ]
-       ]
-      "
-
-    "Created: 10.7.1996 / 15:08:20 / cg"
-    "Modified: 14.10.1996 / 16:59:18 / cg"
+    "Modified: 31.8.1997 / 08:05:32 / cg"
 ! !
 
 !QuerySignal class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.19 1997-06-28 18:24:11 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.20 1997-09-02 17:40:17 cg Exp $'
 ! !