From f37e90436a21a906d3cef536871c3e1913a4a2b7 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Thu, 20 Nov 2014 14:40:13 +0100 Subject: renamed Process::callback to "onComplete" --- history.txt | 1 + threads.js | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/history.txt b/history.txt index c26599c..bb6eac8 100755 --- a/history.txt +++ b/history.txt @@ -2326,3 +2326,4 @@ ______ ------ * Lists: Fixed #642 avoid “freezing” when calling CONS on non-list/null * Threads: Fixed #364 avoid “freezing” when calling LAUNCH on empty ring +* Threads: Added optional “onComplete” callback to Process, thanks, @bromagosa! diff --git a/threads.js b/threads.js index d1209bf..f210380 100644 --- a/threads.js +++ b/threads.js @@ -237,8 +237,8 @@ ThreadManager.prototype.removeTerminatedProcesses = function () { } if (proc.topBlock instanceof ReporterBlockMorph) { - if (proc.callback) { - proc.callback(proc.homeContext.inputs[0]) + if (proc.onComplete instanceof Function) { + proc.onComplete(proc.homeContext.inputs[0]); } else { if (proc.homeContext.inputs[0] instanceof List) { proc.topBlock.showBubble( @@ -301,9 +301,9 @@ ThreadManager.prototype.findProcess = function (block) { are children receiver object (sprite) to which the process applies, cached from the top block - context the Context describing the current state + context the Context describing the current state of this process - homeContext stores information relevant to the whole process, + homeContext stores information relevant to the whole process, i.e. its receiver, result etc. isPaused boolean indicating whether to pause readyToYield boolean indicating whether to yield control to @@ -311,16 +311,17 @@ ThreadManager.prototype.findProcess = function (block) { readyToTerminate boolean indicating whether the stop method has been called isDead boolean indicating a terminated clone process - timeout msecs after which to force yield - lastYield msecs when the process last yielded - errorFlag boolean indicating whether an error was encountered + timeout msecs after which to force yield + lastYield msecs when the process last yielded + errorFlag boolean indicating whether an error was encountered prompter active instance of StagePrompterMorph httpRequest active instance of an HttpRequest or null pauseOffset msecs between the start of an interpolated operation 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 + onComplete an optional callback function to be executed when + the process is done */ Process.prototype = {}; @@ -328,7 +329,7 @@ Process.prototype.contructor = Process; Process.prototype.timeout = 500; // msecs after which to force yield Process.prototype.isCatchingErrors = true; -function Process(topBlock, callback) { +function Process(topBlock, onComplete) { this.topBlock = topBlock || null; this.readyToYield = false; @@ -345,7 +346,7 @@ function Process(topBlock, callback) { this.pauseOffset = null; this.frameCount = 0; this.exportResult = false; - this.callback = callback; + this.onComplete = onComplete || null; if (topBlock) { this.homeContext.receiver = topBlock.receiver(); @@ -444,7 +445,6 @@ Process.prototype.pauseStep = function () { Process.prototype.evaluateContext = function () { var exp = this.context.expression; this.frameCount += 1; - if (exp instanceof Array) { return this.evaluateSequence(exp); } @@ -484,7 +484,9 @@ Process.prototype.evaluateBlock = function (block, argCount) { } if (this.isCatchingErrors) { try { - this.returnValueToParentContext(rcvr[block.selector].apply(rcvr, inputs)); + this.returnValueToParentContext( + rcvr[block.selector].apply(rcvr, inputs) + ); this.popContext(); } catch (error) { this.handleError(error, block); -- cgit v1.3.1