kopia lustrzana https://github.com/backface/turtlestitch
commit
63a1d2ee3a
41
threads.js
41
threads.js
|
@ -136,7 +136,8 @@ ThreadManager.prototype.toggleProcess = function (block) {
|
|||
ThreadManager.prototype.startProcess = function (
|
||||
block,
|
||||
isThreadSafe,
|
||||
exportResult
|
||||
exportResult,
|
||||
callback
|
||||
) {
|
||||
var active = this.findProcess(block),
|
||||
top = block.topBlock(),
|
||||
|
@ -149,7 +150,7 @@ ThreadManager.prototype.startProcess = function (
|
|||
this.removeTerminatedProcesses();
|
||||
}
|
||||
top.addHighlight();
|
||||
newProc = new Process(block.topBlock());
|
||||
newProc = new Process(block.topBlock(), callback);
|
||||
newProc.exportResult = exportResult;
|
||||
this.processes.push(newProc);
|
||||
return newProc;
|
||||
|
@ -236,18 +237,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,6 +320,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
|
||||
*/
|
||||
|
||||
Process.prototype = {};
|
||||
|
@ -322,7 +328,7 @@ Process.prototype.contructor = Process;
|
|||
Process.prototype.timeout = 500; // msecs after which to force yield
|
||||
Process.prototype.isCatchingErrors = true;
|
||||
|
||||
function Process(topBlock) {
|
||||
function Process(topBlock, callback) {
|
||||
this.topBlock = topBlock || null;
|
||||
|
||||
this.readyToYield = false;
|
||||
|
@ -339,6 +345,7 @@ function Process(topBlock) {
|
|||
this.pauseOffset = null;
|
||||
this.frameCount = 0;
|
||||
this.exportResult = false;
|
||||
this.callback = callback;
|
||||
|
||||
if (topBlock) {
|
||||
this.homeContext.receiver = topBlock.receiver();
|
||||
|
@ -436,8 +443,8 @@ Process.prototype.pauseStep = function () {
|
|||
|
||||
Process.prototype.evaluateContext = function () {
|
||||
var exp = this.context.expression;
|
||||
|
||||
this.frameCount += 1;
|
||||
|
||||
if (exp instanceof Array) {
|
||||
return this.evaluateSequence(exp);
|
||||
}
|
||||
|
@ -477,9 +484,7 @@ 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);
|
||||
|
|
Ładowanie…
Reference in New Issue