renamed Process::callback to "onComplete"

pull/3/merge
jmoenig 2014-11-20 14:40:13 +01:00
rodzic 63a1d2ee3a
commit f37e90436a
2 zmienionych plików z 15 dodań i 12 usunięć

Wyświetl plik

@ -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!

Wyświetl plik

@ -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);