diff options
| author | Bernat Romagosa <bromagosa@dosta.net> | 2014-11-19 09:34:59 +0100 |
|---|---|---|
| committer | Bernat Romagosa <bromagosa@dosta.net> | 2014-11-19 09:34:59 +0100 |
| commit | 91690adb29633368ec458ca510086c3b17e0490f (patch) | |
| tree | 3de8eeab9d6938343da6e7c4c64d5ef523117453 /threads.js | |
| parent | f537f62ace4092e1f46d0ca54577ea8810e7510a (diff) | |
| download | snap-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.js | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -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); |
