summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorBernat Romagosa <bromagosa@dosta.net>2014-11-19 09:34:59 +0100
committerBernat Romagosa <bromagosa@dosta.net>2014-11-19 09:34:59 +0100
commit91690adb29633368ec458ca510086c3b17e0490f (patch)
tree3de8eeab9d6938343da6e7c4c64d5ef523117453 /threads.js
parentf537f62ace4092e1f46d0ca54577ea8810e7510a (diff)
downloadsnap-91690adb29633368ec458ca510086c3b17e0490f.tar.gz
snap-91690adb29633368ec458ca510086c3b17e0490f.zip
callback is only executed when the outmost block returns a value
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js38
1 files changed, 20 insertions, 18 deletions
diff --git a/threads.js b/threads.js
index 4592e92..4522d35 100644
--- a/threads.js
+++ b/threads.js
@@ -137,7 +137,7 @@ ThreadManager.prototype.startProcess = function (
block,
isThreadSafe,
exportResult,
- callback
+ callback
) {
var active = this.findProcess(block),
top = block.topBlock(),
@@ -236,18 +236,22 @@ ThreadManager.prototype.removeTerminatedProcesses = function () {
}
if (proc.topBlock instanceof ReporterBlockMorph) {
- if (proc.homeContext.inputs[0] instanceof List) {
- proc.topBlock.showBubble(
- new ListWatcherMorph(
- proc.homeContext.inputs[0]
- ),
- proc.exportResult
- );
+ if (proc.callback) {
+ proc.callback(proc.homeContext.inputs[0])
} else {
- proc.topBlock.showBubble(
- proc.homeContext.inputs[0],
- proc.exportResult
- );
+ if (proc.homeContext.inputs[0] instanceof List) {
+ proc.topBlock.showBubble(
+ new ListWatcherMorph(
+ proc.homeContext.inputs[0]
+ ),
+ proc.exportResult
+ );
+ } else {
+ proc.topBlock.showBubble(
+ proc.homeContext.inputs[0],
+ proc.exportResult
+ );
+ }
}
}
} else {
@@ -315,7 +319,7 @@ ThreadManager.prototype.findProcess = function (block) {
and when the process was paused
exportResult boolean flag indicating whether a picture of the top
block along with the result bubble shoud be exported
- callback a function to be executed when the process is done
+ callback a function to be executed when the process is done
*/
Process.prototype = {};
@@ -340,7 +344,7 @@ function Process(topBlock, callback) {
this.pauseOffset = null;
this.frameCount = 0;
this.exportResult = false;
- this.callback = callback;
+ this.callback = callback;
if (topBlock) {
this.homeContext.receiver = topBlock.receiver();
@@ -439,7 +443,7 @@ Process.prototype.pauseStep = function () {
Process.prototype.evaluateContext = function () {
var exp = this.context.expression;
this.frameCount += 1;
-
+
if (exp instanceof Array) {
return this.evaluateSequence(exp);
}
@@ -479,9 +483,7 @@ Process.prototype.evaluateBlock = function (block, argCount) {
}
if (this.isCatchingErrors) {
try {
- var result = rcvr[block.selector].apply(rcvr, inputs);
- if (this.callback) { this.callback(result) };
- this.returnValueToParentContext(result);
+ this.returnValueToParentContext(rcvr[block.selector].apply(rcvr, inputs));
this.popContext();
} catch (error) {
this.handleError(error, block);