summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorJens Mönig <jens@moenig.org>2014-11-20 14:26:56 +0100
committerJens Mönig <jens@moenig.org>2014-11-20 14:26:56 +0100
commit63a1d2ee3a6eb3a34ed26f316b85f266a584b3e3 (patch)
tree3892e9fd29b9d5aeb9aa9cec66f3750fa6be041b /threads.js
parent3f0b94334dbfd2e5af335999a2b751e3e74a8b93 (diff)
parent91690adb29633368ec458ca510086c3b17e0490f (diff)
downloadsnap-yow-63a1d2ee3a6eb3a34ed26f316b85f266a584b3e3.tar.gz
snap-yow-63a1d2ee3a6eb3a34ed26f316b85f266a584b3e3.zip
Merge pull request #641 from bromagosa/contribution
Added callback to Process
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js41
1 files changed, 23 insertions, 18 deletions
diff --git a/threads.js b/threads.js
index c6b0fde..d1209bf 100644
--- a/threads.js
+++ b/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);