Browse Source

Dispatcher reruns itself when dirtied.

Herbert Vojčík 12 years ago
parent
commit
45679f1e01

+ 17 - 2
js/Trapped-Common.deploy.js

@@ -23,8 +23,23 @@ needsToRun=true;
 return needsToRun;
 };
 })]);
-return needsToRun;
-}
+smalltalk.send(self,"_dirty_",[needsToRun]);
+return self}
+}),
+smalltalk.TrappedDispatcher);
+
+smalltalk.addMethod(
+"_dirty_",
+smalltalk.method({
+selector: "dirty:",
+fn: function (aBoolean){
+var self=this;
+if(smalltalk.assert(aBoolean)){
+smalltalk.send((function(){
+return smalltalk.send(self,"_run",[]);
+}),"_fork",[]);
+};
+return self}
 }),
 smalltalk.TrappedDispatcher);
 

+ 24 - 4
js/Trapped-Common.js

@@ -25,11 +25,31 @@ needsToRun=true;
 return needsToRun;
 };
 })]);
-return needsToRun;
-},
+smalltalk.send(self,"_dirty_",[needsToRun]);
+return self},
 args: ["path"],
-source: "changed: path\x0a\x09| needsToRun |\x0a    needsToRun := false.\x0a\x09self do: [ :each |\x0a\x09\x09| aPath lesser |\x0a\x09\x09aPath := each second.\x0a\x09\x09lesser := aPath size min: path size.\x0a\x09\x09(path copyFrom: 1 to: lesser) = (aPath copyFrom: 1 to: lesser) ifTrue: [\x0a\x09\x09\x09each at: 1 put: true.\x0a            needsToRun := true.\x0a\x09\x09]\x0a\x09].\x0a\x09^needsToRun",
-messageSends: ["do:", "second", "min:", "size", "ifTrue:", "at:put:", "=", "copyFrom:to:"],
+source: "changed: path\x0a\x09| needsToRun |\x0a    needsToRun := false.\x0a\x09self do: [ :each |\x0a\x09\x09| aPath lesser |\x0a\x09\x09aPath := each second.\x0a\x09\x09lesser := aPath size min: path size.\x0a\x09\x09(path copyFrom: 1 to: lesser) = (aPath copyFrom: 1 to: lesser) ifTrue: [\x0a\x09\x09\x09each at: 1 put: true.\x0a            needsToRun := true.\x0a\x09\x09]\x0a\x09].\x0a\x09self dirty: needsToRun",
+messageSends: ["do:", "second", "min:", "size", "ifTrue:", "at:put:", "=", "copyFrom:to:", "dirty:"],
+referencedClasses: []
+}),
+smalltalk.TrappedDispatcher);
+
+smalltalk.addMethod(
+"_dirty_",
+smalltalk.method({
+selector: "dirty:",
+category: 'action',
+fn: function (aBoolean){
+var self=this;
+if(smalltalk.assert(aBoolean)){
+smalltalk.send((function(){
+return smalltalk.send(self,"_run",[]);
+}),"_fork",[]);
+};
+return self},
+args: ["aBoolean"],
+source: "dirty: aBoolean\x0a\x09aBoolean ifTrue: [[ self run ] fork]",
+messageSends: ["ifTrue:", "fork", "run"],
 referencedClasses: []
 }),
 smalltalk.TrappedDispatcher);

+ 1 - 0
js/Trapped-Frontend.deploy.js

@@ -7,6 +7,7 @@ selector: "add:",
 fn: function (aTriplet){
 var self=this;
 smalltalk.send(self["@queue"],"_add_",[aTriplet]);
+smalltalk.send(self,"_dirty_",[smalltalk.send(aTriplet,"_first",[])]);
 return self}
 }),
 smalltalk.TrappedDumbDispatcher);

+ 3 - 2
js/Trapped-Frontend.js

@@ -8,10 +8,11 @@ category: 'accessing',
 fn: function (aTriplet){
 var self=this;
 smalltalk.send(self["@queue"],"_add_",[aTriplet]);
+smalltalk.send(self,"_dirty_",[smalltalk.send(aTriplet,"_first",[])]);
 return self},
 args: ["aTriplet"],
-source: "add: aTriplet\x0a\x09queue add: aTriplet\x0a\x09",
-messageSends: ["add:"],
+source: "add: aTriplet\x0a\x09queue add: aTriplet.\x0a    self dirty: aTriplet first\x0a\x09",
+messageSends: ["add:", "dirty:", "first"],
 referencedClasses: []
 }),
 smalltalk.TrappedDumbDispatcher);

+ 5 - 1
st/Trapped-Common.st

@@ -27,7 +27,11 @@ changed: path
             needsToRun := true.
 		]
 	].
-	^needsToRun
+	self dirty: needsToRun
+!
+
+dirty: aBoolean
+	aBoolean ifTrue: [[ self run ] fork]
 !
 
 run

+ 2 - 1
st/Trapped-Frontend.st

@@ -6,7 +6,8 @@ TrappedDispatcher subclass: #TrappedDumbDispatcher
 !TrappedDumbDispatcher methodsFor: 'accessing'!
 
 add: aTriplet
-	queue add: aTriplet
+	queue add: aTriplet.
+    self dirty: aTriplet first
 ! !
 
 !TrappedDumbDispatcher methodsFor: 'enumeration'!